use std::mem;
use crate::{depot, depot::arena::linked::slots};
pub mod ends;
#[repr(transparent)]
pub struct Fifo<Tag = ()> {
pub(in crate::depot::arena::linked) state: slots::State<Tag>,
}
impl<Tag> Default for Fifo<Tag> {
fn default() -> Self {
Self::new()
}
}
impl<Tag> Fifo<Tag> {
pub const fn new() -> Self {
Self {
state: slots::State::new(),
}
}
pub const fn len(&self) -> usize {
self.state.count().get()
}
pub const fn is_empty(&self) -> bool {
self.state.is_empty()
}
pub fn back(&self) -> Option<Back<Tag>> {
let index = slots::Index::new(self.state.back_index()?);
Some(Back { index })
}
}
const _: () = assert!(mem::size_of::<Fifo>() == 3 * mem::size_of::<u32>());
#[must_use]
#[repr(transparent)]
pub struct Back<Tag> {
index: slots::Index<Tag>,
}
impl<Tag> Back<Tag> {
pub(in crate::depot::arena::linked) const fn into_index(self) -> slots::Index<Tag> {
self.index
}
}
const _: () = assert!(mem::size_of::<Back<()>>() == mem::size_of::<u32>());
impl<Tag> Fifo<Tag> {
pub(in crate::depot) unsafe fn queue<'a, T>(
&'a mut self,
store: &'a slots::Store<T>,
) -> slots::Bound<'a, T, Tag> {
unsafe { self.state.bind(store) }
}
}
#[derive(Debug)]
pub enum Detach {}
#[derive(Debug)]
pub enum Prepend {}
#[derive(Debug)]
pub enum Append {}
#[derive(Debug)]
pub enum Join {}
impl depot::raw::Sealed for Detach {}
impl depot::Predicate for Detach {}
impl depot::raw::Sealed for Prepend {}
impl depot::Predicate for Prepend {}
impl depot::raw::Sealed for Append {}
impl depot::Predicate for Append {}
impl depot::raw::Sealed for Join {}
impl depot::Predicate for Join {}