steel_core/entity/
identity.rs1use std::sync::atomic::{AtomicU64, Ordering};
2
3static LAST_ENTITY_GENERATION: AtomicU64 = AtomicU64::new(0);
4
5#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct EntityGeneration(u64);
11
12impl EntityGeneration {
13 pub(super) fn next() -> Self {
14 let Ok(previous) =
15 LAST_ENTITY_GENERATION.try_update(Ordering::Relaxed, Ordering::Relaxed, |last| {
16 last.checked_add(1)
17 })
18 else {
19 panic!("exhausted entity generations");
20 };
21 Self(previous + 1)
22 }
23}