o3 0.62.0

shared-nothing primitives
Documentation
//! Region-owned FIFO lanes with fair unit admission embedded in their sidecars.

use std::{cell, mem, num};

pub use lanes::Lanes;

use crate::depot::capacity;

mod lanes;
pub mod raw;

#[derive(Clone, Copy, Eq, PartialEq)]
pub struct Plan {
    slots: capacity::Count,
    lanes: num::NonZero<u32>,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Error {
    ZeroLanes { capacity: usize },
    CapacityBelowLanes { capacity: usize, lanes: usize },
    Capacity(capacity::Error),
}

const _: [(); mem::size_of::<Plan>()] = [(); 2 * mem::size_of::<u32>()];

impl Plan {
    pub fn new(capacity: usize, lanes: usize) -> Result<Self, Error> {
        if capacity < lanes {
            return Err(Error::CapacityBelowLanes { capacity, lanes });
        }
        let lanes = num::NonZero::new(lanes).ok_or(Error::ZeroLanes { capacity })?;
        let slots = capacity::Count::try_from(capacity).map_err(Error::Capacity)?;
        Ok(Self {
            slots,
            lanes: capacity::Count::try_nonzero(lanes).map_err(Error::Capacity)?,
        })
    }
}

pub struct State<S> {
    value: S,
    held: cell::Cell<capacity::Count>,
    index: capacity::Count,
}

impl<S> State<S> {
    pub const fn value(&self) -> &S {
        &self.value
    }
}