Releases: huandu/go-clone
New feature: Struct tags to skip or shadow-copy a field while cloning
Changes
- [NEW] Add new struct tags per discussion in #20
clone:"skip"
orclone:"-"
: Skip a field so that the field will be a zero value after cloned.clone:"shadowcopy"
: Copy a field by value (a.k.a. shadow copy).
Full Changelog: v1.6.0...v1.7.0
New feature: `Allocator` is upgraded to a tree-like structure and holds all customizations
Per discussions in #13, in order to make all customizations separated in different allocators, Allocator
holds all customizations inside it now. That is, we can create a new Allocator
instance a
and call a.MarkAsScalar(t)
to mark t
as scalar only in the a
without changing global default. What's more, Allocator
s are organized with a tree-like structure. One Allocator
can inherit its parent's customizations automatically.
Per discussions in #11, Allocator.Clone
and Allocator.CloneSlowly
can be called in the func of SetCustomFunc
without worrying about dead loop. That means, if we can call allocator.Clone(old)
clone the old value in custom function then update some fields in the cloned value and finally set the cloned value to the new to return the value. It's useful when we need to hack very few fields in a complex type with lots of fields when cloning.
Full Changelog: v1.5.0...v1.6.0
New feature: Support arena and custom allocator
To support Go1.20 arena and other memory management APIs, there is a new type Allocator
to enable us to take full control over memory allocation when cloning.
There is a breaking change in type Func which is used by SetCustomFunc
. Hopefully, this would not break many users.
Full Changelog: v1.4.1...v1.5.0
New sub-package `github.com/huandu/go-clone/generic` with generic APIs
Package clone
supports generic now!
- For users who want to opt-in Go generic syntax for cleaner APIs, new package
github.com/huandu/go-clone/generic
is your best choice. To import this package, Go 1.18+ is required. - For users who are not ready for Go 1.18+, you can continue to stick on
github.com/huandu/go-clone
.
All features of these two packages will be the same in the future.