Macro dyn_clone::clone_trait_object [−][src]
Implement the standard library Clone
for a trait object that has
DynClone
as a supertrait.
use dyn_clone::DynClone; trait MyTrait: DynClone { /* ... */ } dyn_clone::clone_trait_object!(MyTrait); // Now data structures containing Box<dyn MyTrait> can derive Clone. #[derive(Clone)] struct Container { trait_object: Box<dyn MyTrait>, }
The macro supports traits that have type parameters and/or where
clauses.
use dyn_clone::DynClone; use std::io::Read; trait Difficult<R>: DynClone where R: Read { /* ... */ } dyn_clone::clone_trait_object!(<R> Difficult<R> where R: Read);