Expand description
ShallowClone trait to make it easier to work with copy-on-write values efficiently.
This is basically the same as the standard Clone, except that it’s optimized for copy-on-write
values so that they’re not cloned. Shallow cloning a Cow will always produce
a Borrowed variant, either referencing the original value if it was Owned, or the value that the
original value referenced if it already was Borrowed.
This crate also introduces a MakeOwned trait which is the opposite of ShallowClone.
It takes any value that implements the trait and returns an equivalent which is 'static - no references,
completely self-sufficient.
Additionally this crate introduces two replacements for the standard Cow<'a, T>:
CoCow<'a, T>which is a general replacement for the standardCow,CoCowSlice<'a, T>which is a specialised replacement forCow<'a, [T]>.
These types are covariant over T, which solves some problems if your T contains references.
In most cases you probably won’t need them, standard Cow works perfectly for
things like Cow<'a, str> or Cow<'a, [u8]>, but if your
T contains references, the standard Cow will not let you subtype them
after shallow cloning, and you will end up with 2 different lifetimes.
CoCow and CoCowSlice solve this problem.
Enums§
- CoCow
- Covariant copy-on-write. This is a simpler version of
Cowthat doesn’t rely onToOwnedtrait and is covariant overT. - CoCow
Slice - Covariant copy-on-write slice. This is a specialised version of
CoCowfor slices and allows you to have slices without an underlying allocated type like Vec if you wish.
Traits§
- Make
Owned - Takes a value and transforms it to be
'static, cloning parts if necessary - Shallow
Clone - The same as
Clone, but doesnt cloneCowvalues, instead it just borrows them.
Derive Macros§
- Make
Owned - Automatically derives the
MakeOwnedtrait - Shallow
Clone - Automatically derives the
ShallowClonetrait