ike/
id.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2
3static NEXT_ID: AtomicU64 = AtomicU64::new(0);
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct Id(pub u64);
7
8impl Default for Id {
9    #[inline]
10    fn default() -> Self {
11        Self::new()
12    }
13}
14
15impl Id {
16    #[inline]
17    pub fn new() -> Self {
18        let inner = NEXT_ID.fetch_add(1, Ordering::SeqCst);
19
20        Self(inner)
21    }
22}
23
24impl Into<egui::TextureId> for Id {
25    #[inline]
26    fn into(self) -> egui::TextureId {
27        egui::TextureId::User(self.0)
28    }
29}
30
31pub trait HasId {
32    fn id(&self) -> Id;
33}