From 8b9d906cc4923fdf6f2b860e0da2ab00f1993796 Mon Sep 17 00:00:00 2001 From: Wojciech Polak Date: Mon, 19 Aug 2024 09:04:19 +0200 Subject: [PATCH] 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. --- core/http/src/status.rs | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/core/http/src/status.rs b/core/http/src/status.rs index f90e40f240..1aa882f438 100644 --- a/core/http/src/status.rs +++ b/core/http/src/status.rs @@ -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(&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 { - 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::*;