I have a complex data structure, which defines a type P, and I'd like to perform a deep copy of an instance of such a data structure. I have found this library but, considering the semantics of the Go language, wouldn't a method like the following be more idiomatic?:
func (receiver P) copy() *P{
return &receiver
}
Since the method receives a value of type P (and values are always passed by copy), the result should be a reference to a deep copy of the source, like in this example:
src := new(P)
dcp := src.copy()
Indeed,
src != dst => true
reflect.DeepEqual(*src, *dst) => true