Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
Clone returns a deep copy of passed argument. The cloned value will be identical to the source value. Cloned pointers will point to a new object with the same value as in the source. This also works for nested values, such as parts of collections (arrays, slices, and maps) or fields of passed structs. It additionally guarantied that if two or more pointers at the source object references to the same value, clones pointers will refers to same vallue. But if two or more slices at the source object refer to the same memory area (i.e. the same underlying array), the copy will refer to different arrays. By default, unexported struct fields will be shallow copied, but this can be changed with functional options. Unsupported types (channels and funcs) will be shallow copied by default, but this can also be changed with functional options. Unsafe pointers will be treated like ordinary values.
Example ¶
package main import ( "fmt" "github.com/LastPossum/kamino" ) func main() { tests := []any{ 200000, `units are ready, with a`, 1000000, []string{ "more well", "on the way.", }, map[string]any{ "I don't like sand": "It's coarse and rough and irritating and it gets everywhere.", }, } for _, expected := range tests { actual, err := kamino.Clone(expected, kamino.WithErrOnUnsupported()) if err != nil { fmt.Println("got error:", err) } fmt.Println(actual) } }
Output: 200000 units are ready, with a 1000000 [more well on the way.] map[I don't like sand:It's coarse and rough and irritating and it gets everywhere.]
func WithErrOnUnsupported ¶
func WithErrOnUnsupported() func(*config)
WithErrOnUnsupported is a functional option for the Clone function. When this setting is enabled, attempting to clone channels and functions, even if they are nested, will result in an error.
func WithExpectedPtrsCount ¶
func WithExpectedPtrsCount(cnt int) func(*config)
WithExpectedPtrsCount is a functional option for the Clone function that sets the initial capacity for the pointers map used during the cloning process. If the amount of pointers in the source object is known and rather big, this setting could reduce allocations and improve performance.
func WithForceUnexported ¶
func WithForceUnexported() func(*config)
WithForceUnexported is a functional option for the Clone function. When this setting is enabled, unexported fields will be cloned forcefully.
func WithZeroUnexported ¶
func WithZeroUnexported() func(*config)
WithZeroUnexported is a functional option for the Clone function. When this setting is enabled, unexported fields will be forcefully set to zero value of their kind.
Types ¶
This section is empty.