123456789101112131415161718192021222324252627282930//对任何实现特定trait类型有条件的实现traittrait GetName { fn get_name(&self) -> &String; }trait PrintName { fn print_name(&self); }//对泛型T实现了PrintName特征,前提是T实现了GetName//有点类似继承impl<T:GetName> PrintName for T { fn print_name(&self) { println!("name = {}",self.get_name()); } }struct Student { name: String, }impl GetName for Student { fn get_name(&self) -> &String { &(self.name) } }fn main() { let s = Student { name: String::from("xiaohuang") }; s.print_name(); }