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