Expand description
The Clone
trait for types that cannot be ‘implicitly copied’.
In Rust, some simple types are “implicitly copyable” and when you
assign them or pass them as arguments, the receiver will get a copy,
leaving the original value in place. These types do not require
allocation to copy and do not have finalizers (i.e., they do not
contain owned boxes or implement Drop
), so the compiler considers
them cheap and safe to copy. For other types copies must be made
explicitly, by convention implementing the Clone
trait and calling
the clone
method.
Basic usage example:
To easily implement the Clone trait, you can also use
#[derive(Clone)]
. Example:
Traits§
- A common trait for the ability to explicitly duplicate an object.
- Clone
ToUninit Experimental A generalization ofClone
to dynamically-sized types stored in arbitrary containers.
Derive Macros§
- Derive macro generating an impl of the trait
Clone
.