blob: abc5991b4604039f411036ea2f5ec8e58b29d06b (
plain)
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
27
28
29
30
|
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),
}
}
}
|