Skip to content

Commit 949e2cd

Browse files
authored
Merge pull request #58 from hashmismatch/integer_hash_eq
Hash & Eq traits for the built-in wrapper types
2 parents 3172999 + 6a840dc commit 949e2cd

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

packed_struct/src/internal_prelude/no_std.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use core::mem;
1313
pub use core::intrinsics::write_bytes;
1414
pub use core::ops::Deref;
1515
pub use core::slice;
16+
pub use core::hash::{Hash, Hasher};
1617

1718
#[cfg(feature="alloc")]
1819
pub use alloc::vec::Vec;

packed_struct/src/internal_prelude/std.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ pub use std::sync::Arc;
2222
pub use std::str::from_utf8;
2323
pub use std::ops::Deref;
2424
pub use std::slice;
25+
pub use std::hash::{Hash, Hasher};

packed_struct/src/types_num.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ impl<T, B> PartialEq for Integer<T, B> where T: PartialEq {
5656
}
5757
}
5858

59+
impl<T, B> Eq for Integer<T, B> where T: Eq {}
60+
61+
impl<T, B> Hash for Integer<T, B> where T: Hash {
62+
fn hash<H: Hasher>(&self, state: &mut H) {
63+
self.num.hash(state);
64+
}
65+
}
66+
5967
impl<T, B> Integer<T, B> where Self: Copy {
6068
/// Convert into a MSB packing helper
6169
pub fn as_packed_msb(&self) -> MsbInteger<T, B, Self> {

packed_struct/src/types_reserved.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait ReservedBitValue {
1515
}
1616

1717
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
18-
#[derive(Default, Copy, Clone, PartialEq)]
18+
#[derive(Default, Copy, Clone, PartialEq, Eq, Hash)]
1919
pub struct BitOne;
2020
impl ReservedBitValue for BitOne {
2121
fn get_reserved_bit_value_byte() -> u8 {
@@ -24,7 +24,7 @@ impl ReservedBitValue for BitOne {
2424
}
2525

2626
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
27-
#[derive(Default, Copy, Clone, PartialEq)]
27+
#[derive(Default, Copy, Clone, PartialEq, Eq, Hash)]
2828
pub struct BitZero;
2929
impl ReservedBitValue for BitZero {
3030
fn get_reserved_bit_value_byte() -> u8 {
@@ -34,7 +34,7 @@ impl ReservedBitValue for BitZero {
3434

3535
/// Always packs into the associated bit value. Ignores the input when unpacking.
3636
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
37-
#[derive(Default, Copy, Clone, PartialEq)]
37+
#[derive(Default, Copy, Clone, PartialEq, Eq, Hash)]
3838
pub struct ReservedBits<V, B> {
3939
value: V,
4040
bits: PhantomData<B>

0 commit comments

Comments
 (0)