Skip to content

Commit 8b9d906

Browse files
frondeusSergioBenitez
authored andcommitted
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 rwf2#2844.
1 parent 327b1ad commit 8b9d906

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

core/http/src/status.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl StatusClass {
112112
/// }
113113
/// # }
114114
/// ```
115-
#[derive(Debug, Clone, Copy)]
115+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
116116
pub struct Status {
117117
/// The HTTP status code associated with this status.
118118
pub code: u16,
@@ -354,32 +354,6 @@ impl fmt::Display for Status {
354354
}
355355
}
356356

357-
impl std::hash::Hash for Status {
358-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
359-
self.code.hash(state)
360-
}
361-
}
362-
363-
impl PartialEq for Status {
364-
fn eq(&self, other: &Self) -> bool {
365-
self.code.eq(&other.code)
366-
}
367-
}
368-
369-
impl Eq for Status { }
370-
371-
impl PartialOrd for Status {
372-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
373-
Some(self.cmp(other))
374-
}
375-
}
376-
377-
impl Ord for Status {
378-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
379-
self.code.cmp(&other.code)
380-
}
381-
}
382-
383357
#[cfg(feature = "serde")]
384358
mod serde_impl {
385359
use super::*;

0 commit comments

Comments
 (0)