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