Generic implementation depending on traits
问题 When defining a generic struct , is there a way in Rust to use different implementation of a method according to which trait is implemented by the given generic type T ? For example: struct S<T> { value: T, } impl<T> S<T> { fn print_me(&self) { println!("I cannot be printed"); } } impl<T: std::fmt::Display> S<T> { fn print_me(&self) { println!("{}", self.value); } } fn main() { let s = S { value: 2 }; s.print_me(); } 回答1: There is an unstable feature known as specialization which permits