o3 0.62.0

shared-nothing primitives
Documentation
use std::{cell, mem, num::NonZero};

use crate::depot::queue::links;
#[repr(transparent)]
pub struct Free(cell::Cell<Option<links::Index>>);

impl Free {
    pub fn seeded(cap: usize) -> Self {
        Self(cell::Cell::new(
            (cap != 0).then_some(links::Index::from(NonZero::<u32>::MIN)),
        ))
    }

    pub fn front(&self) -> Option<links::Index> {
        self.0.get()
    }

    /// # Safety
    /// This hook is the free head. The caller overwrites its links before they are observed.
    pub(in crate::depot) unsafe fn acquire_hook(&self, hook: &links::Hook) {
        self.0.set(hook.next_index());
    }

    pub fn recycle(&self, vacant: links::Detached<'_>) {
        let (hook, index) = vacant.into_parts();
        hook.previous.set(index.raw());
        hook.next.set(links::Index::encode(self.0.get()));
        self.0.set(Some(index));
    }
}

const _: () = assert!(mem::size_of::<Free>() == mem::size_of::<u32>());