1 use std::fmt::Debug; 2 3 use intertrait::cast::*; 4 use intertrait::*; 5 6 struct Data; 7 8 trait Source: CastFrom {} 9 10 trait Concat<T: Debug> { 11 type I1: Debug; 12 type I2: Debug; 13 14 fn concat(&self, prefix: T, a: Self::I1, b: Self::I2) -> String; 15 } 16 17 #[cast_to] 18 impl Concat<String> for Data { 19 type I1 = i32; 20 type I2 = &'static str; 21 22 fn concat(&self, prefix: String, a: Self::I1, b: Self::I2) -> String { 23 format!("{}: {} - {}", prefix, a, b) 24 } 25 } 26 27 impl Source for Data {} 28 29 #[test] 30 fn test_cast_to_on_trait_impl_with_assoc_type3() { 31 let data = Data; 32 let source: &dyn Source = &data; 33 let concat = source.cast::<dyn Concat<String, I1 = i32, I2 = &'static str>>(); 34 assert_eq!( 35 concat.unwrap().concat("Data".to_owned(), 101, "hello"), 36 "Data: 101 - hello" 37 ); 38 } 39