o3 0.62.0

shared-nothing primitives
Documentation
//! Counted FIFO state over external linked slots.

use std::mem;

use crate::depot::{self, arena::linked, capacity};

pub mod ends;

/// Compact counted FIFO state stored outside its linked node arena.
#[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>()];

/// One observed live FIFO tail in a linked-node domain.
#[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>()];

/// The current front belongs to this owner. A supplied successor comes from that exact
/// slot, after detachment and before the next endpoint or slot mutation.
#[derive(Debug)]
pub enum Detach {}

/// The live slot is detached from the stable destination in the same store.
/// At the front it links to the prior head. At the back it has no successor.
/// A supplied previous endpoint remains exact and linked through publication.
#[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>>;

/// The exact endpoints delimit a stable nonempty source disjoint from the destination.
/// Its ownership transfers to that destination in the same store.
/// The unchanged prior tail already links to the source head; neither chain is reentered before publication.
#[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 {}