use std::mem;
use crate::depot::{self, arena::linked, capacity};
pub mod ends;
#[repr(C)]
pub struct Fifo<Tag = ()> {
pub(in crate::depot) links: ends::Exclusive<linked::raw::Index<Tag>>,
pub(in crate::depot::arena::linked) len: u32,
}
impl<Tag> Default for Fifo<Tag> {
fn default() -> Self {
Self::new()
}
}
impl<Tag> Fifo<Tag> {
pub const fn new() -> Self {
Self {
links: ends::Exclusive::empty(),
len: 0,
}
}
pub const fn len(&self) -> usize {
self.len as usize
}
pub const fn is_empty(&self) -> bool {
self.len == 0
}
pub fn back(&self) -> Option<Back<Tag>> {
let index = self.links.tail_raw();
index.get()?;
Some(Back { index })
}
pub(in crate::depot) const fn count(&self) -> capacity::Count {
capacity::Count::new(self.len)
}
}
const _: [(); mem::size_of::<Fifo>()] = [(); 3 * mem::size_of::<u32>()];
#[must_use]
#[repr(transparent)]
pub struct Back<Tag> {
index: linked::raw::Index<Tag>,
}
impl<Tag> Back<Tag> {
pub(in crate::depot) const fn into_index(self) -> linked::raw::Index<Tag> {
self.index
}
}
const _: [(); mem::size_of::<Back<()>>()] = [(); mem::size_of::<u32>()];
#[derive(Debug)]
pub enum Detach {}
#[derive(Debug)]
pub enum Insert<const FRONT: bool> {}
pub(in crate::depot) type Insertion<O, I, const FRONT: bool> =
depot::raw::Proof<(O, I, Option<I>), Insert<FRONT>>;
#[derive(Debug)]
pub enum Join {}
type Joined<O, L> = depot::raw::Proof<(O, L, L, Option<<L as depot::raw::Link>::Item>), Join>;
impl depot::raw::Sealed for Detach {}
impl<const FRONT: bool> depot::raw::Sealed for Insert<FRONT> {}
impl depot::raw::Sealed for Join {}