1 use intertrait::cast::*; 2 use intertrait::*; 3 4 #[cast_to(Greet)] 5 struct Data; 6 7 trait Source: CastFrom {} 8 9 trait Greet { 10 fn greet(&self); 11 } 12 13 impl Greet for Data { 14 fn greet(&self) { 15 println!("Hello"); 16 } 17 } 18 19 impl Source for Data {} 20 21 #[test] 22 fn test_cast_to_on_struct() { 23 let data = Data; 24 let source: &dyn Source = &data; 25 let greet = source.cast::<dyn Greet>(); 26 greet.unwrap().greet(); 27 } 28