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
use std::{fmt::Debug, hash::Hash};

pub struct Hashed<T> {
    pub value: T,
    pub hash: u64,
}

impl<T> Hashed<T> {
    pub fn new(value: T) -> Self
    where
        T: Hash,
    {
        let hash = fxhash::hash64(&value);
        Self { value, hash }
    }
}

impl<T> Debug for Hashed<T>
where
    T: Debug,
{
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.value.fmt(f)
    }
}