o3 0.60.0

shared-nothing primitives
Documentation
use std::{marker, ops};

use crate::depot::{
    queue::{indexed::slab, links},
    raw,
};

/// An affine link retained inside its allocation-owning ledger.
#[repr(transparent)]
pub(in crate::depot::queue::group) struct Node<Tag>(
    links::Index,
    marker::PhantomData<slab::Handle<Tag>>,
);

impl<Tag> Node<Tag> {
    pub(in crate::depot::queue::group) fn new(index: links::Index) -> Self {
        Self(index, marker::PhantomData)
    }

    pub(in crate::depot::queue::group) fn index(&self) -> links::Index {
        self.0
    }

    pub(in crate::depot::queue::group) fn inserted(key: slab::Handle<Tag>) -> Self {
        Self::new(links::Index::from(key))
    }

    pub(in crate::depot::queue::group) fn bind<T, H, const N: usize, C, S>(
        &self,
        source: S,
    ) -> S::Output
    where
        H: raw::IndexedHook,
        C: raw::Count,
        S: ops::Deref<Target = slab::Slab<T, Tag, { u32::MAX }, H, N, C>>
            + raw::Project<links::Index, H>,
    {
        // SAFETY: only the ledger owning both this affine link and its allocation
        // can borrow Node. Unlinking consumes the link before retiring its slot.
        unsafe { source.project(self.0) }
    }
}

const _: () = {
    assert!(size_of::<Node<()>>() == size_of::<links::Index>());
    assert!(size_of::<Option<Node<()>>>() == size_of::<links::Index>());
};