#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct WuiTypeId {
pub low: u64,
pub high: u64,
}
impl WuiTypeId {
#[inline]
#[must_use]
pub fn of<T: 'static>() -> Self {
Self::from_type_name(core::any::type_name::<T>())
}
#[inline]
#[must_use]
pub const fn from_runtime(_type_id: core::any::TypeId, name: &'static str) -> Self {
Self::from_type_name(name)
}
#[inline]
#[must_use]
pub const fn from_type_name(name: &str) -> Self {
let hash = fnv1a_128(name.as_bytes());
#[expect(
clippy::cast_possible_truncation,
reason = "deliberately keeps only the low 64 bits of the 128-bit hash; the high 64 bits are captured separately below, so no bits are lost"
)]
let low = hash as u64;
Self {
low,
high: (hash >> 64) as u64,
}
}
}
const fn fnv1a_128(bytes: &[u8]) -> u128 {
const FNV_OFFSET: u128 = 0x6c62_272e_07bb_0142_62b8_2175_6295_c58d;
const FNV_PRIME: u128 = 0x0000_0000_0100_0000_0000_0000_0000_013b;
let mut hash = FNV_OFFSET;
let mut i = 0;
while i < bytes.len() {
hash ^= bytes[i] as u128;
hash = hash.wrapping_mul(FNV_PRIME);
i += 1;
}
hash
}