use std::sync::atomic::{AtomicU64, Ordering}; static NEXT_UID: AtomicU64 = AtomicU64::new(0); /// Unique entity ID. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Uid { inner: u64, } impl Uid { pub fn new(uid: u64) -> Self { debug_assert!( uid < NEXT_UID.load(Ordering::Relaxed), "Invalid entity UID {uid}" ); Self { inner: uid } } pub fn new_unique() -> Self { Self { inner: NEXT_UID.fetch_add(1, Ordering::Relaxed), } } }