Thanks for your contribution, and I do have a suggestion which may make this library better.
I'm using this library to write a code generator with generics, and I cannot predict which specific type the user may call.
type DeepCopyGen[T any] interface {
DeepCopyInto(*T)
}
func DeepCopy[T any](in, out *T) {
var _in any = in
if d, ok := _in.(DeepCopyGen[T]); ok {
// use deepcopy-gen
d.DeepCopyInto(out)
return
}
// Have to call pcopy.Preheat each time
pcopy.Copy(in, out, pcopy.WithUsePreheat())
}
if pcopy.Copy enables preheat by default, then things go easy. Just call pcopy.Copy(in, out) is enough.
The process could be as follows:
- split
getFromCacheSetAndRun into get and run, the get function returns (*allFieldFunc, bool)
- if
get returns nil, false, call newAllFieldFunc and saveToCache
- call
*allFieldFunc.do
- the
opts ...Option argument can be removed
What do you think? @guonaihong
Thanks for your contribution, and I do have a suggestion which may make this library better.
I'm using this library to write a code generator with generics, and I cannot predict which specific type the user may call.
if
pcopy.Copyenables preheat by default, then things go easy. Just callpcopy.Copy(in, out)is enough.The process could be as follows:
getFromCacheSetAndRunintogetandrun, thegetfunction returns(*allFieldFunc, bool)getreturnsnil, false, callnewAllFieldFuncandsaveToCache*allFieldFunc.doopts ...Optionargument can be removedWhat do you think? @guonaihong