Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829use std::sync::atomic::Ordering;
use portable_atomic::AtomicU64;
/// Counter that returns unique IDs.pub struct IdCounter { value: AtomicU64,}
impl IdCounter { pub const fn new() -> Self { Self { // Start from 1 to reduce the possibility that some other code that uses these IDs will // get confused. value: AtomicU64::new(1), } }
pub fn next(&self) -> u64 { self.value.fetch_add(1, Ordering::Relaxed) }}
impl Default for IdCounter { fn default() -> Self { Self::new() }}