use core::fmt::{Display, Formatter};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SlotId(u16);
impl SlotId {
#[must_use]
pub const fn new(n: u16) -> Self {
Self(n)
}
#[must_use]
pub const fn get(self) -> u16 {
self.0
}
#[must_use]
pub const fn index(self) -> usize {
self.0 as usize
}
}
impl Display for SlotId {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(test)]
#[allow(non_snake_case)]
mod seal__slot_tests {
use super::*;
use alloc::string::ToString;
#[test]
fn slot_id__new_get_index_display_order() {
let s = SlotId::new(17);
assert_eq!(s.get(), 17);
assert_eq!(s.index(), 17_usize);
assert_eq!(s.to_string(), "17");
assert!(SlotId::new(1) < SlotId::new(2));
assert_eq!(SlotId::default(), SlotId::new(0));
}
}