Skip to main content

datex_core/traits/
datex_hash.rs

1use core::hash::{Hash, Hasher};
2
3use crate::collections::default_hasher;
4
5/// A trait for types that can be hashed using the default hasher
6/// This trait is automatically implemented for all types that implement [core::hash::Hash].
7pub trait DatexHash {
8    fn datex_hash(&self, state: &mut dyn Hasher);
9
10    fn datex_hash_default(&self) -> u64 {
11        let mut hasher = default_hasher();
12        self.datex_hash(&mut hasher);
13        hasher.finish()
14    }
15}
16
17pub macro impl_datex_hash($t:ty) {
18    impl DatexHash for $t {
19        fn datex_hash(&self, mut state: &mut dyn Hasher) {
20            self.hash(&mut state);
21        }
22    }
23}