3 ms·
Generic traits can be implemented multiple times, as long as the params differ. This is generally used to establish relationships between types, which can natur
by Gankro 10y ago
Generic traits can be implemented multiple times, as long as the params differ. This is generally used to establish relationships between types, which can naturally be M:N. Comparison and conversion are standard use cases:
impl PartialOrd<OsString> for OsString
impl PartialOrd<str> for OsString
impl PartialOrd<OsStr> for OsString
impl PartialOrd<Cow<OsStr>> for OsString
Traits without generics can only be implemented once (because there's no generic params to "differentiate" impls). But it's often still desirable/necessary to relate types to the implementation. This is much more common, as it's generally a case that some type is a ThingDoer in only one way (and having it be a ThingDoer in more than one way may be confusing).
Associated types are often more convenient and give the compiler more room to reason about your code.