observe/
hashed.rs

1use std::fmt::Debug;
2use std::hash::Hash;
3use std::ops::Deref;
4
5pub struct Hashed<T> {
6	pub value: T,
7	pub hash: u64,
8}
9
10impl<T> PartialEq for Hashed<T> {
11	fn eq(&self, other: &Self) -> bool {
12		self.hash == other.hash
13	}
14}
15
16impl<T> Hashed<T> {
17	pub fn new(value: T) -> Self
18	where
19		T: Hash,
20	{
21		let hash = fxhash::hash64(&value);
22		Self { value, hash }
23	}
24}
25
26impl<T> Deref for Hashed<T> {
27	type Target = T;
28	fn deref(&self) -> &Self::Target {
29		&self.value
30	}
31}
32
33impl<T> Debug for Hashed<T>
34where
35	T: Debug,
36{
37	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38		self.value.fmt(f)
39	}
40}