1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::prelude::*;
macro_rules! impl_int {
($P:ty, $N:ty) => {
impl StableHash for $P {
fn stable_hash<H: StableHasher>(&self, sequence_number: H::Seq, state: &mut H) {
profile_method!(stable_hash);
AsInt {
is_negative: false,
little_endian: &self.to_le_bytes(),
}
.stable_hash(sequence_number, state)
}
}
impl StableHash for $N {
fn stable_hash<H: StableHasher>(&self, sequence_number: H::Seq, state: &mut H) {
profile_method!(stable_hash);
AsInt {
is_negative: self.is_negative(),
little_endian: &self.wrapping_abs().to_le_bytes(),
}
.stable_hash(sequence_number, state)
}
}
};
}
impl_int!(u128, i128);
impl_int!(u64, i64);
impl_int!(u32, i32);
impl_int!(u16, i16);
impl_int!(u8, i8);
impl_int!(usize, isize);