-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PartialOrd and Ord for http::Uri #407
Comments
Do you have a use case in mind for this? Could you share? |
Deriving the PartialOrd and Ord traits on types that contain the |
Do those types of yours suggest any particular ordering for the (self.authority().host(), self.authority().port(), self.scheme(), self.path_and_query()) ...in that order, as being more natural. |
As far as I remember, there was no particular reason, why I proposed the above implementation. It was meant as a suggestion, how this could be implemented. I think it does not even matter that the ordering makes sense (for my use case), because I only wanted it, so I do not have to implement PartialEq, Eq, PartialOrd, Ord and Hash manually for the structs that use http::Uri internally. (All the trait implementations have to agree with each other). I am not very familiar with this crate, so I do not know if your ordering is more natural, but my proposal would work with crates that use |
(self.authority(), self.scheme(), self.path_and_query()) As far as implementation, it might be better to avoid the conditional for impl PartialOrd for Uri {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Uri {
fn cmp(&self, r: &Self) -> Ordering {
(self.authority(), self.scheme(), self.path_and_query())
.cmp(&(r.authority(), r.scheme(), r.path_and_query()))
}
} ...unless I'm missing something about that? Users can still new-type the |
I thought about an implementation like this
the problem is the components only implement
PartialOrd
.Another option would be:
The text was updated successfully, but these errors were encountered: