o3 0.62.0

shared-nothing primitives
Documentation
use std::cell;

use crate::depot::queue::links;

/// One allocation-free head-only indexed list.
#[repr(transparent)]
pub struct List(cell::Cell<u32>);

impl Default for List {
    fn default() -> Self {
        Self::new()
    }
}

impl List {
    pub const fn new() -> Self {
        Self(cell::Cell::new(links::Index::END))
    }

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

    pub fn is_empty(&self) -> bool {
        self.0.get() == links::Index::END
    }
}
impl List {
    pub(in crate::depot) fn first(&self) -> Option<links::Index> {
        links::Index::decode(self.0.get())
    }

    /// # Safety
    /// This exact list retains its initialized non-sentinel head.
    pub unsafe fn front_key(&self) -> links::Index {
        unsafe { links::Index::new_raw(self.0.get()) }
    }

    pub(in crate::depot) fn set(&self, index: Option<links::Index>) {
        self.0.set(links::Index::encode(index));
    }
}

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