o3 0.60.0

shared-nothing primitives
Documentation
use crate::{
    alloc,
    depot::{
        self, capacity,
        index::Initialized,
        queue::{
            indexed::planes::{bound, resident},
            links,
        },
    },
};

impl<'storage, 'id, T, M, const N: usize, P: Ord, C: alloc::raw::Extent, const E: usize>
    resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>
{
    /// # Safety
    /// Every row linked in E is active and vacant. The owner seeds only None rows
    /// and returns rows to E only after their value and old keys are retired.
    pub unsafe fn available(
        &mut self,
    ) -> Option<resident::Available<'_, 'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>>
    {
        const { assert!(E < N) };
        let index = self.source.core.queues[E].first()?;
        // SAFETY: the caller's private FREE invariant retains this active row.
        let key = bound::ActiveKey(capacity::Key::new(unsafe { depot::raw::Proof::new(index) }));
        Some(resident::Available { source: self, key })
    }
}

impl<'id> resident::Key<'id> {
    pub fn from_live<
        'loan,
        'storage,
        T,
        M,
        const N: usize,
        P: Ord,
        C: alloc::raw::Extent,
        const E: usize,
    >(
        source: depot::raw::Proof<
            (
                &'loan resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>,
                links::Index,
            ),
            Initialized<resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>>,
        >,
    ) -> Self {
        let (_, index) = source.into_inner();
        // SAFETY: the retained proof names an initialized row in this exact branded owner.
        Self(bound::ActiveKey(capacity::Key::new(unsafe {
            depot::raw::Proof::new(index)
        })))
    }
}

// SAFETY: this resident owner retains the same initialized row throughout the loan.
unsafe impl<
    'loan,
    'storage,
    'id,
    T,
    M,
    const N: usize,
    P: Ord,
    C: alloc::raw::Extent,
    const E: usize,
>
    depot::raw::Project<
        links::Index,
        resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>,
    > for &'loan resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>
{
    type Output = &'loan T;

    unsafe fn project(self, index: links::Index) -> Self::Output {
        // SAFETY: Project retains this same initialized row and its original owner.
        let key = resident::Key::from_live(unsafe { depot::raw::Proof::new((self, index)) });
        self.get(key)
    }
}