pub trait ImplicitClone: Clone {
// Provided method
fn implicit_clone(&self) -> Self { ... }
}
Expand description
Provided Methodsยง
Sourcefn implicit_clone(&self) -> Self
fn implicit_clone(&self) -> Self
This function is not magic; it is literally defined as
โ
fn implicit_clone(&self) -> Self {
self.clone()
}
It is useful when you want to clone but also ensure that the type implements
ImplicitClone
.
Examples:
use implicit_clone::ImplicitClone;
let x: u32 = Default::default();
let clone = ImplicitClone::implicit_clone(&x);
โ
use implicit_clone::ImplicitClone;
let x: Vec<u32> = Default::default();
// does not compile because Vec<_> does not implement ImplicitClone
let clone = ImplicitClone::implicit_clone(&x);
Dyn Compatibilityยง
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.