1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//!
//!clonar objectos traits sin usar unsafe
//!
//! ```
//!
//! use clonable_trait_object::clonable_trait_object;
//!
//! /*El primer parametro es el trait objetivo
//! el segundo parametro es el nombre que le daras al trait
//! que hara de Clone*/
//!clonable_trait_object!(Animal,AnimalClone);
//!trait Animal: AnimalClone {
//! fn speak(&self);
//!}
//!#[derive(Clone,Debug)]
//!struct Dog {
//! name: String,
//!}
//!impl Dog {
//! fn new(name: &str) -> Dog {
//! Dog {
//! name: name.to_string(),
//! }
//! }
//!}
//!impl Animal for Dog {
//! fn speak(&self) {
//! println!("{}: ruff, ruff!", self.name);
//! }
//!}
//!#[derive(Clone)]
//!struct AnimalHouse {
//! animal: Box<dyn Animal>,
//!}
//! fn main() {
//! let house = AnimalHouse {
//! animal: Box::new(Dog::new("Bobby")),
//! };
//! let house2 = house.clone();
//! house2.animal.speak();
//!}
//! ```
//!
//!