o3 0.60.0

shared-nothing primitives
Documentation
use cycle::Policy;

use crate::depot::{
    arena::slab::{
        self, entries, entry,
        key::{self, cycle},
        storage,
    },
    index::Initialized,
    queue::links,
};

impl<'a, T, Tag, const MAX: u32, const RECYCLE: bool, const PARTITIONS: usize>
    slab::Occupied<entries::Busy<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS>, Tag>
where
    cycle::Mode<RECYCLE>: Policy,
{
    /// Consumes a live root projection into its selected exclusive slot.
    pub fn from_live<C, P>(
        live: Live<'a, T, Tag, C, P, MAX, RECYCLE, PARTITIONS>,
    ) -> (
        slab::Occupied<entries::Busy<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS, P>, Tag>,
        C,
    ) {
        // SAFETY: the projection retains the original exclusive owner and context.
        let live = unsafe { live.map(|((slab, context), index)| ((&slab.core, context), index)) };
        let (busy, context) = live.into();
        (slab::Occupied::new(busy), context)
    }
}

impl<T, Tag, const MAX: u32, M: entries::Mode, const N: usize, P, const ROOT: bool>
    slab::Occupied<entries::Busy<'_, T, MAX, M, N, P>, Tag, ROOT>
{
    pub fn key(&self) -> key::Handle<Tag, MAX> {
        key::Handle::new(self.entry.index(), self.entry.generation())
    }

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

impl<
    T,
    Tag,
    const MAX: u32,
    M: entries::Mode,
    const N: usize,
    P,
    S: storage::Storage,
    const ROOT: bool,
    K,
> entry::Slot<entries::Busy<'_, T, MAX, M, N, P, S>, Tag, ROOT, K>
{
    /// Drops the value in place and returns its slot to the free list or retirement.
    pub fn discard(self) {
        self.entry.discard();
    }
}

impl<'a, T, Tag, const MAX: u32, const RECYCLE: bool, const PARTITIONS: usize, P, const ROOT: bool>
    slab::Occupied<entries::Busy<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS, P>, Tag, ROOT>
where
    cycle::Mode<RECYCLE>: Policy,
{
    pub fn get(&self) -> &T {
        self.entry.value()
    }

    pub fn get_mut(&mut self) -> &mut T {
        self.entry.value_mut()
    }

    pub fn into_mut(self) -> &'a mut T {
        self.entry.into_mut()
    }

    /// Withdraws the value while retaining its owner, identity, and operation plane.
    pub fn take(self) -> Withdrawn<'a, T, Tag, P, MAX, RECYCLE, PARTITIONS, ROOT> {
        let (pending, value) = self.entry.withdraw();
        (slab::Withdrawn::new(pending), value)
    }
}

impl<'a, T, Tag, const MAX: u32, const RECYCLE: bool, const PARTITIONS: usize, P>
    slab::Occupied<entries::Busy<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS, P>, Tag>
where
    cycle::Mode<RECYCLE>: Policy,
{
    /// Projects a live neighbor while retaining the whole storage owner's exclusive loan.
    pub fn project<Q>(
        live: crate::depot::raw::Proof<(&Self, links::Index), Initialized<Q>>,
    ) -> (key::Handle<Tag, MAX>, &T) {
        let index = *live.key();
        // SAFETY: the occupied guard owns this exact core for its full borrow.
        let live = unsafe { live.map(|(entry, index)| (&entry.entry, index)) };
        let (epoch, value) = entries::Busy::project(live);
        (key::Handle::new(index.raw(), epoch), value)
    }
}

type Live<'a, T, Tag, C, P, const MAX: u32, const RECYCLE: bool, const PARTITIONS: usize> =
    crate::depot::raw::Proof<
        (
            (&'a mut slab::Store<T, Tag, MAX, RECYCLE, PARTITIONS>, C),
            links::Index,
        ),
        Initialized<P>,
    >;

type Withdrawn<
    'a,
    T,
    Tag,
    P,
    const MAX: u32,
    const RECYCLE: bool,
    const PARTITIONS: usize,
    const ROOT: bool,
> = (
    slab::Withdrawn<
        entries::Issued<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS, P>,
        Tag,
        ROOT,
    >,
    T,
);