intuicio_data/
type_hash.rs

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
26
use rustc_hash::FxHasher;
use std::hash::{Hash, Hasher};

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TypeHash {
    hash: u64,
}

impl TypeHash {
    pub fn of<T: ?Sized>() -> Self {
        unsafe { Self::raw(std::any::type_name::<T>()) }
    }

    /// # Safety
    pub unsafe fn raw(name: &str) -> Self {
        let mut hasher = FxHasher::default();
        name.hash(&mut hasher);
        Self {
            hash: hasher.finish(),
        }
    }

    pub fn hash(&self) -> u64 {
        self.hash
    }
}