// 条件trait trait GetName { fn get_name(&self) -> String; } trait ShowName { fn show_name(&self); } impl ShowName for T { fn show_name(&self) { println!("{}", self.get_name()); } } struct Stu { name: String, } impl GetName for Stu { fn get_name(&self) -> String { return self.name.clone(); } } fn main() { let s = Stu { name: String::from("root"), }; s.show_name(); }