From c1f82d935b8ee29a43e8dbf0d7b59efbd749b479 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 23 Feb 2024 11:08:29 +0100 Subject: [PATCH] Derive PartialEq, Eq, PartialOrd, Ord, Hash The derived implementations work now that the interior value is always fully masked[1]. As a side effect, this makes consts eligible for pattern matching. [1]: https://github.com/rust-ux/uX/pull/65 Closes: https://github.com/rust-ux/uX/issues/66 --- src/lib.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f860a9b..a8f1dcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,10 +25,6 @@ use lib::core::ops::{ ShrAssign, }; -use lib::core::hash::{Hash, Hasher}; - -use lib::core::cmp::{Ord, Ordering, PartialOrd}; - use lib::core::fmt::{Binary, Display, Formatter, LowerHex, Octal, UpperHex}; macro_rules! define_unsigned { @@ -37,7 +33,7 @@ macro_rules! define_unsigned { #[$doc] #[allow(non_camel_case_types)] - #[derive(Default, Clone, Copy, Debug)] + #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $name($type); impl $name { @@ -61,7 +57,7 @@ macro_rules! define_signed { #[$doc] #[allow(non_camel_case_types)] - #[derive(Default, Clone, Copy, Debug)] + #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $name($type); #[$doc] @@ -159,32 +155,6 @@ macro_rules! implement_common { } } - impl PartialEq for $name { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } - } - - impl Eq for $name {} - - impl PartialOrd for $name { - fn partial_cmp(&self, other: &$name) -> Option { - Some(self.cmp(other)) - } - } - - impl Ord for $name { - fn cmp(&self, other: &$name) -> Ordering { - self.0.cmp(&other.0) - } - } - - impl Hash for $name { - fn hash(&self, h: &mut H) { - self.0.hash(h) - } - } - // Implement formating functions impl Display for $name { fn fmt(&self, f: &mut Formatter) -> Result<(), lib::core::fmt::Error> {