use core::fmt;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Default, Ord, PartialOrd)]
pub struct ResourceId(u32);
impl ResourceId {
pub const fn new(id: u32) -> Self {
Self(id)
}
pub const fn get(&self) -> u32 {
self.0
}
pub const fn from_bytes_le(bytes: &[u8]) -> Self {
const FNV_OFFSET_BASIS: u32 = 0x811c_9dc5;
const FNV_PRIME: u32 = 0x0100_0193;
let mut hash = FNV_OFFSET_BASIS;
let mut i = 0;
while i < bytes.len() {
hash ^= bytes[i] as u32;
hash = hash.wrapping_mul(FNV_PRIME);
i += 1;
}
Self(hash)
}
}
impl fmt::Debug for ResourceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ResourceId({:#010x})", self.0)
}
}