#[derive(DeepClone)]
{
// Attributes available to this derive:
#[deepclone]
}
Expand description
Derive DeepClone, cloning every field through the same Cloner.
Structs (named, tuple, and unit), enums, generics, and where-clauses are supported. Unions
are not, unless #[deepclone(clone)] makes the fields irrelevant. Every type parameter gains a DeepClone bound, as derive(Clone) adds a Clone
bound.
Nothing here inspects field types: Rc and Arc reach the cloner through their own
DeepClone impls, so Vec<Rc<T>> and HashMap<K, Rc<T>> work too, which a derive
matching on the literal token Rc would miss.
No 'static bound is added, so a generic type with an Rc<..T..> field needs T: 'static
on its own declaration.
§Field attributes
#[deepclone(clone)]— useClone::clone, which on anRcshares the allocation. Preferrable (and correct) when nothing reachable through the field can be mutated.#[deepclone(with = path)]— callpath(&field, cloner).#[deepclone(default)]— ignore the source value and useDefault::default().
§Container attributes
#[deepclone(clone)]— clone the whole value withClone::cloneinstead of field by field. The right answer for a type that reaches nothing shared, since it asks nothing of the field types, so they need noDeepCloneimpl of their own. Bounds each type parameter byClonerather thanDeepClone.#[deepclone(bound = "T: MyBound")]— replace the generated bounds, for when aDeepClonebound on every parameter is too strong.