use std::{
fmt,
sync::atomic::{AtomicUsize, Ordering},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(usize);
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
impl WindowId {
#[must_use]
pub fn new() -> Self {
Self(NEXT_ID.fetch_add(1, Ordering::Relaxed))
}
#[must_use]
pub const fn from_raw(id: usize) -> Self {
Self(id)
}
#[must_use]
pub const fn as_usize(&self) -> usize {
self.0
}
}
impl Default for WindowId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for WindowId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "window:{}", self.0)
}
}
#[cfg(test)]
#[path = "tests/window_id.rs"]
mod tests;