use crate::depot::queue::links;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(in crate::buffer::pool) struct Key<const ACCOUNT: bool = false>(u32);
impl<const ACCOUNT: bool> Key<ACCOUNT> {
pub(super) const unsafe fn new(index: u32) -> Self {
Self(unsafe { links::Index::new_raw(index) }.raw())
}
pub(super) const fn get(self) -> u32 {
self.0
}
pub(super) const unsafe fn decode(word: u32) -> Option<Self> {
match links::Index::decode(word) {
Some(index) => Some(Self(index.raw())),
None => None,
}
}
pub(super) const fn encode(key: Option<Self>) -> u32 {
links::Index::encode(match key {
Some(key) => Some(unsafe { links::Index::new_raw(key.0) }),
None => None,
})
}
}
const _: () = {
assert!(size_of::<Key>() == size_of::<u32>());
assert!(size_of::<Key<true>>() == size_of::<u32>());
};