stable_hash/impls/
ints.rs

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