use core::fmt::Display;
use std::{
num::NonZeroUsize,
sync::atomic::{AtomicUsize, Ordering},
};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct StoreId(NonZeroUsize);
impl Default for StoreId {
fn default() -> Self {
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
Self(NonZeroUsize::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}
impl Display for StoreId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let val: usize = self.0.into();
if val == usize::MAX {
write!(f, "unknown")
} else {
write!(f, "{}", self.0)
}
}
}