Derive equality, ordering traits for http::Status.

`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.
This commit is contained in:
Wojciech Polak 2024-08-19 09:04:19 +02:00 committed by Sergio Benitez
parent 327b1ad064
commit 8b9d906cc4
1 changed files with 1 additions and 27 deletions

View File

@ -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,
@ -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::*;