reprint

package module
v0.0.0-...-722754a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 3 Imported by: 12

README

Reprint

Reprint is a Go library to deep copy any object THE RIGHT WAY ™

reprint

Join Slack channel Build Status

GitHub last commit GitHub commit activity GitHub issues

Features

Unlike most libraries out there, this one deep copies by assigning new pointers to all data structures nested in a given object, hence doing it THE RIGHT WAY ™

It works with slices, arrays, maps, pointers, nested pointers, nils, structs (with unexported fields too), functions and channels.

Limits:

  • Functions pointers are not changed but that's by design
  • Channels buffered elements are not deep copied

Usage

go get -u github.com/qdm12/reprint

You can check out Golang Playground and activate Imports at the top, or read this:

package main

import (
    "fmt"

    "github.com/qdm12/reprint"
)

func main() {
    one := 1
    two := 2
    type myType struct{ A *int }

    // reprint.FromTo usage:
    var x, y myType
    x.A = &one
    reprint.FromTo(&x, &y) // you can check the error returned also
    y.A = &two
    fmt.Println(x.A, *x.A) // 0xc0000a0010 1
    fmt.Println(y.A, *y.A) // 0xc0000a0018 2

    // reprint.This usage:
    x2 := myType{&one}
    out := reprint.This(x2)
    y2 := out.(myType)
    y2.A = &two
    fmt.Println(x2.A, *x2.A) // 0xc0000a0010 1
    fmt.Println(y2.A, *y2.A) // 0xc0000a0018 2
}

Development

  1. Install Docker
    • On Windows, share a drive with Docker Desktop and have the project on that partition
    • On OSX, share your project directory with Docker Desktop
  2. With Visual Studio Code, install the remote containers extension
  3. In Visual Studio Code, press on F1 and select Remote-Containers: Open Folder in Container...
  4. Your dev environment is ready to go!... and it's running in a container 👍

TODOs

  • (Research) deep copy elements currently in channel
    • Race conditions
    • Pause channel?
  • Polish FromTo
    • Initialize copy to copy's type if it's a typed nil
    • Initialize copy to original's type if it's an untyped nil
    • Returns typed nil instead of untyped nil if original is a nil pointer (typed)
  • forceCopyValue might not be needed

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTo

func FromTo(original, copy interface{}) error

FromTo deep copies original and assigns the copy to the copy argument (pointer).

func This

func This(original interface{}) (copy interface{})

This deep copies original and returns the copy as an interface.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL