Documentation ¶
Overview ¶
Package dyad makes deep copies of arbitrary values.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
Clone returns a deep copy of src.
Example ¶
package main import ( "fmt" "github.com/dogmatiq/dyad" ) func main() { type Value struct { Data map[any]any } src := Value{ Data: map[any]any{ "key": "original value", }, } dst := dyad.Clone(src) dst.Data["key"] = "altered value" fmt.Println(src.Data["key"]) fmt.Println(dst.Data["key"]) }
Output: original value altered value
Types ¶
type ChannelStrategy ¶
type ChannelStrategy int
ChannelStrategy is an enumeration of strategies that can be used by Clone() when a channel is encountered.
const ( // PanicOnChannel causes Clone() to panic when it encounters a // channel. // // This is the default behavior. PanicOnChannel ChannelStrategy = iota // original and cloned values. ShareChannels // IgnoreChannels causes Clone() to use a nil value when a channel is // encountered. IgnoreChannels )
type Option ¶
type Option func(*cloneOptions)
An Option changes the behavior of a clone operation.
The signature of this function is not part of the public API and may change at any time without warning.
func WithChannelStrategy ¶
func WithChannelStrategy(s ChannelStrategy) Option
WithChannelStrategy is an option that controls how Clone() behaves when it encounters a channel.
func WithUnexportedFieldStrategy ¶
func WithUnexportedFieldStrategy(s UnexportedFieldStrategy) Option
WithUnexportedFieldStrategy is an option that controls how Clone() behaves when it encounters an unexported field.
type UnexportedFieldStrategy ¶
type UnexportedFieldStrategy int
UnexportedFieldStrategy is an enumeration of strategies that can be used by Clone() when an unexported struct field is encountered.
const ( // PanicOnUnexportedField causes Clone() to panic when it encounters an // unexported struct field. // // This is the default behavior. PanicOnUnexportedField UnexportedFieldStrategy = iota // CloneUnexportedFields causes Clone() to clone unexported struct fields // just as it would any other value. CloneUnexportedFields // IgnoreUnexportedFields causes Clone() to skip cloning of unexported // struct fields, leaving them as their zero value. IgnoreUnexportedFields )