<!-- {{# generate.module_header{} #}} -->
# Module :: clone_dyn
[](https://github.com/emersion/stability-badges#experimental) [](https://github.com/Wandalen/wTools/actions/workflows/ModuleCloneDynPush.yml) [](https://docs.rs/clone_dyn) [](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=sample%2Frust%2Fclone_dyn_trivial_sample%2Fsrc%2Fmain.rs,RUN_POSTFIX=--example%20clone_dyn_trivial_sample/https://github.com/Wandalen/wTools) [](https://discord.gg/m3YfbXpUUY)
Derive to clone dyn structures.
The crate's purpose is straightforward: it allows for easy cloning of `dyn< Trait >` with minimal effort and complexity, accomplished by applying the derive attribute to the trait.
### Alternative
There are few alternatives [dyn-clone](https://github.com/dtolnay/dyn-clone), [dyn-clonable](https://github.com/kardeiz/objekt-clonable). Unlike other options, this solution is more concise and demands less effort to use, all without compromising the quality of the outcome. Also, you can ask an inquiry and get answers, which is problematic in the case of alternatives.
### Basic use-case
<!-- begin {{# generate.module_sample( "example/clone_dyn_trivail_sample.rs" ) #}} -->
```rust ignore
#[ cfg( feature = "enabled" ) ]
{
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` */
}
```
<!-- end -->
### To add to your project
```sh
cargo add clone_dyn
```
### Try out from the repository
```sh
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/clone_dyn_trivial
cargo run
```