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
use std::fmt;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct UniqueId(u32);
impl UniqueId {
pub fn new() -> UniqueId {
use std::sync::atomic::{AtomicUsize, Ordering};
lazy_static! {
static ref NEXT_ID: AtomicUsize = AtomicUsize::new(0);
}
UniqueId(NEXT_ID.fetch_add(1, Ordering::SeqCst) as u32)
}
}
impl fmt::Display for UniqueId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}