go-clone

Clone any Go data structure deeply and thoroughly.

MIT License

Stars
288
Committers
1

Bot releases are hidden (Show)

go-clone - New feature: Struct tags to skip or shadow-copy a field while cloning Latest Release

Published by huandu 12 months ago

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: https://github.com/huandu/go-clone/compare/v1.6.0...v1.7.0

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: https://github.com/huandu/go-clone/compare/v1.5.0...v1.6.0

go-clone - New feature: Support arena and custom allocator

Published by huandu over 1 year ago

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: https://github.com/huandu/go-clone/compare/v1.4.1...v1.5.0

go-clone - New sub-package `github.com/huandu/go-clone/generic` with generic APIs

Published by huandu about 2 years ago

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.

Package Rankings
Top 2.14% on Proxy.golang.org
Badges
Extracted from project README
Go Go Doc Go Report Coverage Status