use std::num::NonZeroU64;
use std::sync::atomic::{AtomicU64, Ordering};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct TabId(NonZeroU64);
impl TabId {
pub fn fresh() -> Self {
static COUNTER: AtomicU64 = AtomicU64::new(1);
let raw = COUNTER.fetch_add(1, Ordering::Relaxed);
Self(NonZeroU64::new(raw).expect("TabId counter wrapped to zero"))
}
pub fn from_raw(value: NonZeroU64) -> Self {
Self(value)
}
pub fn raw(self) -> NonZeroU64 {
self.0
}
}
impl std::fmt::Display for TabId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "TabId({})", self.0.get())
}
}