Crate non_std::dependencies::derive_tools::dependencies::clone_dyn
source · [−]Expand description
Derive to clone dyn structures.
Module :: clone_dyn
Derive to clone dyn structures.
The purpose of the crate is very simple, making dyn< Trait >
clonable with minimum efforts and complexity, simply by applying to derive to the trait.
Alternative
There are few alternatives dyn-clone, https://github.com/kardeiz/objekt-clonable. Unlike alternatives, this solution is more compact and requires fewer efforts to use without loss of quality of the solution. Also, you can ask an inquiry and get answers, which is problematic in the case of alternatives.
Sample
use clone_dyn::clone_dyn;
#[ clone_dyn ]
trait Trait1
{
}
let vec = Vec::< Box< dyn Trait1 > >::new();
let vec2 = vec.clone(); /* <- it does not work without `clone_dyn` */
To add to your project
cargo add clone_dyn
Try out from the repository
git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/clone_dyn_trivial
cargo run
Modules
Dependencies.
Exposed namespace of the module.
Orphan namespace of the module.
Prelude to use essentials: use my_module::prelude::*
.
Protected namespace of the module.
Functions
Clone boxed dyn.
Attribute Macros
Derive macro to generate former for a structure. Former is variation of Builder Pattern.