Documentation
¶
Overview ¶
Package deepcopy copies the values the daemon datasets hold in fields typed any, where the concrete type is not known at compile time and so cannot be copied by a hand-written DeepCopy method.
The datasets fill those fields two ways: decoded from a peer's heartbeat message, where the value is whatever encoding/json produces, or set directly by a driver on the local node, where it is any Go value at all. Reflection is what covers both without the callers having to enumerate types they do not control.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any[T any](v T) T
Any returns a deep copy of v.
Maps, slices, arrays, pointers and structs are rebuilt, so no reference is shared with v. Everything else is copied by assignment, which is what a scalar, a string or a chan needs.
Unexported struct fields are copied as they are, since reflection cannot set them. That is correct for the value-like structs that reach here, time.Time among them, and no worse than the json round trip this replaces, which dropped them.
func Slice ¶
func Slice[S ~[]E, E any](s S) S
Slice returns a copy of s sharing no backing array with it, and nil for a nil s, so that a caller serializing the result gets null where it got null and [] where it got [].
The elements are copied by assignment, which is a deep copy only for a slice of values. Use Any for a slice whose elements hold references.
Types ¶
This section is empty.