Skip to content

Releases: huandu/go-clone

New feature: Struct tags to skip or shadow-copy a field while cloning

06 Nov 16:50
Compare
Choose a tag to compare

Changes

  • [NEW] Add new struct tags per discussion in #20
    • clone:"skip" or clone:"-": 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

02 Apr 11:14
e95f5c8
Compare
Choose a tag to compare

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, Allocators 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

10 Feb 16:59
0068aca
Compare
Choose a tag to compare

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

06 Sep 12:00
Compare
Choose a tag to compare

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.