Skip to content

Commit d328e41

Browse files
committed
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]: rust-ux#65 Close: rust-ux#66
1 parent f0c03bd commit d328e41

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

src/lib.rs

+2-32
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ use lib::core::ops::{
2525
ShrAssign,
2626
};
2727

28-
use lib::core::hash::{Hash, Hasher};
29-
30-
use lib::core::cmp::{Ord, Ordering, PartialOrd};
31-
3228
use lib::core::fmt::{Binary, Display, Formatter, LowerHex, Octal, UpperHex};
3329

3430
macro_rules! define_unsigned {
@@ -37,7 +33,7 @@ macro_rules! define_unsigned {
3733

3834
#[$doc]
3935
#[allow(non_camel_case_types)]
40-
#[derive(Default, Clone, Copy, Debug)]
36+
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
4137
pub struct $name($type);
4238

4339
impl $name {
@@ -60,7 +56,7 @@ macro_rules! define_signed {
6056

6157
#[$doc]
6258
#[allow(non_camel_case_types)]
63-
#[derive(Default, Clone, Copy, Debug)]
59+
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
6460
pub struct $name($type);
6561

6662
#[$doc]
@@ -157,32 +153,6 @@ macro_rules! implement_common {
157153
}
158154
}
159155

160-
impl PartialEq for $name {
161-
fn eq(&self, other: &Self) -> bool {
162-
self.0 == other.0
163-
}
164-
}
165-
166-
impl Eq for $name {}
167-
168-
impl PartialOrd for $name {
169-
fn partial_cmp(&self, other: &$name) -> Option<Ordering> {
170-
Some(self.cmp(other))
171-
}
172-
}
173-
174-
impl Ord for $name {
175-
fn cmp(&self, other: &$name) -> Ordering {
176-
self.0.cmp(&other.0)
177-
}
178-
}
179-
180-
impl Hash for $name {
181-
fn hash<H: Hasher>(&self, h: &mut H) {
182-
self.0.hash(h)
183-
}
184-
}
185-
186156
// Implement formating functions
187157
impl Display for $name {
188158
fn fmt(&self, f: &mut Formatter) -> Result<(), lib::core::fmt::Error> {

0 commit comments

Comments
 (0)