Skip to main content

cargo/util/
unhashed.rs

1/// Avoid hashing `T` when included in another type
2#[derive(Copy, Clone, Default, Debug)]
3pub struct Unhashed<T>(pub T);
4
5impl<T> std::hash::Hash for Unhashed<T> {
6    fn hash<H: std::hash::Hasher>(&self, _: &mut H) {
7        // ...
8    }
9}
10
11impl<T> PartialEq for Unhashed<T> {
12    fn eq(&self, _: &Self) -> bool {
13        true
14    }
15}
16
17impl<T> Eq for Unhashed<T> {}
18
19impl<T> PartialOrd for Unhashed<T> {
20    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
21        Some(other.cmp(&self))
22    }
23}
24
25impl<T> Ord for Unhashed<T> {
26    fn cmp(&self, _: &Self) -> std::cmp::Ordering {
27        std::cmp::Ordering::Equal
28    }
29}