Skip to content

Commit 2d0020f

Browse files
authored
Implement Hash Manually (#47)
Addresses a clippy lint that you should not derive `Hash` and implement `PartialEq`.
1 parent cbb3860 commit 2d0020f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::uint::U256;
1313
use core::{mem::MaybeUninit, num::ParseIntError};
1414

1515
/// A 256-bit signed integer type.
16-
#[derive(Clone, Copy, Default, Eq, Hash)]
16+
#[derive(Clone, Copy, Default, Eq)]
1717
#[repr(transparent)]
1818
pub struct I256(pub [i128; 2]);
1919

src/macros/cmp.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ macro_rules! impl_cmp {
44
(
55
impl Cmp for $int:ident ($prim:ident);
66
) => {
7-
impl PartialOrd for $int {
7+
impl ::core::hash::Hash for $int {
88
#[inline]
9-
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
10-
Some(self.cmp(other))
9+
fn hash<H>(&self, hasher: &mut H)
10+
where
11+
H: ::core::hash::Hasher,
12+
{
13+
::core::hash::Hash::hash(&self.0, hasher);
1114
}
1215
}
1316

@@ -36,6 +39,13 @@ macro_rules! impl_cmp {
3639
}
3740
}
3841

42+
impl PartialOrd for $int {
43+
#[inline]
44+
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
45+
Some(self.cmp(other))
46+
}
47+
}
48+
3949
impl PartialOrd<$prim> for $int {
4050
#[inline]
4151
fn partial_cmp(&self, rhs: &$prim) -> Option<::core::cmp::Ordering> {

src/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::I256;
1313
use core::{mem::MaybeUninit, num::ParseIntError};
1414

1515
/// A 256-bit unsigned integer type.
16-
#[derive(Clone, Copy, Default, Eq, Hash)]
16+
#[derive(Clone, Copy, Default, Eq)]
1717
#[repr(transparent)]
1818
pub struct U256(pub [u128; 2]);
1919

0 commit comments

Comments
 (0)