o3 0.49.0

shared-nothing primitives
Documentation
use std::mem;

use crate::depot::{
    capacity,
    queue::{indexed::lanes, links, tagged},
};

pub struct Position<
    'a,
    T,
    const N: usize,
    const L: usize,
    C: crate::depot::raw::Count,
    const INITIALIZED: bool = false,
> {
    pub(in crate::depot) store: &'a mut lanes::Fifo<T, N, C>,
    pub(in crate::depot) index: links::Index,
}

impl<'a, T, const N: usize, const L: usize, C: crate::depot::raw::Count>
    tagged::Vacant<Position<'a, T, N, L, C>>
{
    /// # Safety
    /// The exclusive owner proves this initialized hook is detached and in bounds.
    pub(in crate::depot) unsafe fn detached(
        store: &'a mut lanes::Fifo<T, N, C>,
        index: links::Index,
    ) -> Self {
        const { assert!(L < N) };
        unsafe { tagged::Vacant::new(Position { store, index }) }
    }

    pub fn insert<const FRONT: bool>(self, value: T) -> lanes::Rollback<'a, T, N, C> {
        let Position { store, index } = self.insert_linked::<FRONT>(value).into_inner();
        // SAFETY: insertion established this exact initialized membership and exclusive owner.
        let entry = unsafe { tagged::Linked::new(crate::depot::raw::Proof::new((store, index))) };
        crate::mem::Lease::open(crate::depot::raw::LaneUndo(std::marker::PhantomData), entry)
    }
}

impl<'a, T, const N: usize, C: crate::depot::raw::Count> lanes::Rollback<'a, T, N, C> {
    pub fn commit(self) {
        self.into_parts();
    }

    pub fn remove(self) -> T {
        self.into_parts().1.remove()
    }
}

const _: () = {
    assert!(
        mem::size_of::<tagged::Vacant<Position<'static, (), 1, 0, capacity::Count>>>()
            == 2 * mem::size_of::<usize>()
    );
    assert!(
        mem::size_of::<lanes::Rollback<'static, (), 1, capacity::Count>>()
            == 2 * mem::size_of::<usize>()
    );
    assert!(
        mem::size_of::<Option<lanes::Rollback<'static, (), 1, capacity::Count>>>()
            == 2 * mem::size_of::<usize>()
    );
};