1 use std::fmt::Debug; 2 3 use intertrait::cast::*; 4 use intertrait::*; 5 6 struct I32Data(i32); 7 8 trait Source: CastFrom {} 9 10 trait Producer { 11 type Output: Debug; 12 13 fn produce(&self) -> Self::Output; 14 } 15 16 #[cast_to] 17 impl Producer for I32Data { 18 type Output = i32; 19 20 fn produce(&self) -> Self::Output { 21 self.0 22 } 23 } 24 25 impl Source for I32Data {} 26 27 #[test] 28 fn test_cast_to_on_trait_impl_with_assoc_type1() { 29 let data = I32Data(100); 30 let source: &dyn Source = &data; 31 let producer = source.cast::<dyn Producer<Output = i32>>(); 32 assert_eq!(producer.unwrap().produce(), data.0); 33 } 34