mirror of https://github.com/rwf2/Rocket.git
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:
parent
327b1ad064
commit
8b9d906cc4
|
@ -112,7 +112,7 @@ impl StatusClass {
|
||||||
/// }
|
/// }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
/// The HTTP status code associated with this status.
|
/// The HTTP status code associated with this status.
|
||||||
pub code: u16,
|
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")]
|
#[cfg(feature = "serde")]
|
||||||
mod serde_impl {
|
mod serde_impl {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue