Skip to main content

zenthra_core/
id.rs

1// crates/zenthra-core/src/id.rs
2
3use std::sync::atomic::{AtomicU64, Ordering};
4
5static NEXT_ID: AtomicU64 = AtomicU64::new(1);
6
7/// Unique widget identifier.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct Id(u64);
10
11impl Id {
12    pub fn new() -> Self {
13        Self(NEXT_ID.fetch_add(1, Ordering::Relaxed))
14    }
15
16    pub fn from_u64(id: u64) -> Self {
17        Self(id)
18    }
19
20    pub fn raw(self) -> u64 {
21        self.0
22    }
23}
24
25impl Default for Id {
26    fn default() -> Self {
27        Self::new()
28    }
29}