Skip to content

Commit

Permalink
Derive equality, ordering traits for http::Status.
Browse files Browse the repository at this point in the history
`PartialEq` when not derived results in `StructuralPartialEq` not being
implemented. As this was the case for `http::Status`, matching against
constants like `Status::Unauthorized` was not allowed.

This commit replaces the manual implementations of equality traits
(`PartialEq`, `Eq`) and ordering traits (`PartialOrd`, `Ord`) for
`http::Status` with `#[derive]`.

Resolves #2844.
  • Loading branch information
frondeus authored and SergioBenitez committed Aug 19, 2024
1 parent 327b1ad commit 8b9d906
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions core/http/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl StatusClass {
/// }
/// # }
/// ```
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Status {
/// The HTTP status code associated with this status.
pub code: u16,
Expand Down Expand Up @@ -354,32 +354,6 @@ impl fmt::Display for Status {
}
}

impl std::hash::Hash for Status {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.code.hash(state)
}
}

impl PartialEq for Status {
fn eq(&self, other: &Self) -> bool {
self.code.eq(&other.code)
}
}

impl Eq for Status { }

impl PartialOrd for Status {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Status {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.code.cmp(&other.code)
}
}

#[cfg(feature = "serde")]
mod serde_impl {
use super::*;
Expand Down

0 comments on commit 8b9d906

Please sign in to comment.