How do I reuse code for similar yet distinct types in Rust?
问题 I have a basic type with some functionality, including trait implementations: use std::fmt; use std::str::FromStr; pub struct MyIdentifier { value: String, } impl fmt::Display for MyIdentifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.value) } } impl FromStr for MyIdentifier { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(MyIdentifier { value: s.to_string(), }) } } This is a simplified example, real code would be more complex. I want