In the documentation for Ord
, it says
Implementations must be consistent with the PartialOrd implementation [...]
That of course makes sense and can easily be archived as in the example further down:
impl PartialOrd for MyType {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
I wonder, why they would leave this burden / risk to us users instead of having a blanket impl<T: Ord> PartialOrd for T { /* ... */ }
.
I tested for problems with circular dependencies and stuff in a playground, but that worked as I would expect it. The internet didn't yield any results either.
Another reason I can think of is how the derive
macros work right now. One would probably have to replace every derive(PartialOrd, Ord)
with just derive(Ord)
(or make the macro for PartialOrd
smarter - I don't know if it can become that smart though).
Adding the suggested blanket impl would forbid custom implementations of PartialOrd
and eliminate the requirement for consistency. Of course, that would now be a breaking change in the library. Is that the only reason, or am I missing some other arguments here?