iced-yoda/core/src/window/id.rs

23 lines
508 B
Rust
Raw Normal View History

use std::fmt;
2023-12-02 20:41:58 +01:00
use std::hash::Hash;
use std::sync::atomic::{self, AtomicU64};
2022-06-21 15:59:45 -03:00
/// The id of the window.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
2022-06-21 15:59:45 -03:00
pub struct Id(u64);
2023-12-02 20:41:58 +01:00
static COUNT: AtomicU64 = AtomicU64::new(1);
2022-06-21 15:59:45 -03:00
impl Id {
/// Creates a new unique window [`Id`].
2023-12-02 20:41:58 +01:00
pub fn unique() -> Id {
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
2022-06-21 15:59:45 -03:00
}
}
impl fmt::Display for Id {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}