iced_core/window/
id.rs

1use std::fmt;
2use std::hash::Hash;
3use std::sync::atomic::{self, AtomicU64};
4
5/// The id of the window.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Id(u64);
9
10static COUNT: AtomicU64 = AtomicU64::new(1);
11
12impl Id {
13    /// Creates a new unique window [`Id`].
14    pub fn unique() -> Id {
15        Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
16    }
17}
18
19impl fmt::Display for Id {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        self.0.fmt(f)
22    }
23}