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)]
7pub struct Id(u64);
8
9static COUNT: AtomicU64 = AtomicU64::new(1);
10
11impl Id {
12 /// Creates a new unique window [`Id`].
13 pub fn unique() -> Id {
14 Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
15 }
16}
17
18impl fmt::Display for Id {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 self.0.fmt(f)
21 }
22}