Trait ImplicitClone
pub trait ImplicitClone: Clone {
// Provided method
fn implicit_clone(&self) -> Self { ... }
}
Expand description
Provided Methods§
fn 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.