diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/dyn-clone/examples | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/dyn-clone/examples')
| -rw-r--r-- | vendor/dyn-clone/examples/readme.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/dyn-clone/examples/readme.rs b/vendor/dyn-clone/examples/readme.rs new file mode 100644 index 00000000..41682cd1 --- /dev/null +++ b/vendor/dyn-clone/examples/readme.rs @@ -0,0 +1,26 @@ +use dyn_clone::DynClone; + +trait MyTrait: DynClone { + fn recite(&self); +} + +impl MyTrait for String { + fn recite(&self) { + println!("{} ♫", self); + } +} + +fn main() { + let line = "The slithy structs did gyre and gimble the namespace"; + + // Build a trait object holding a String. + // This requires String to implement MyTrait and std::clone::Clone. + let x: Box<dyn MyTrait> = Box::new(String::from(line)); + + x.recite(); + + // The type of x2 is a Box<dyn MyTrait> cloned from x. + let x2 = dyn_clone::clone_box(&*x); + + x2.recite(); +} |
