o3 0.62.0

shared-nothing primitives
Documentation
use crate::{
    base::marker::ThreadBound,
    depot::queue::ring::{self, inline},
};

/// One inline slot owner with available and pending FIFO lists.
pub struct Pool<T, const N: usize, P: Copy = ()> {
    _thread: ThreadBound,
    pub(in crate::depot::queue::ring) slots: ring::raw::Slots<T, N, P>,
}

impl<T, const N: usize, P: Copy> Pool<T, N, P> {
    pub fn new(values: [T; N]) -> Self {
        Self {
            _thread: ThreadBound::NEW,
            slots: ring::raw::Slots::new(values),
        }
    }

    pub fn try_acquire(&self) -> Result<inline::Lease<'_, T, N, P>, inline::Full> {
        let index = self.slots.acquire().ok_or(inline::Full { capacity: N })?;
        Ok(inline::Lease { pool: self, index })
    }

    pub fn pop_front(&self) -> Option<(inline::Lease<'_, T, N, P>, P)> {
        let (index, payload) = self.slots.take()?;
        Some((inline::Lease { pool: self, index }, payload))
    }

    pub fn is_empty(&self) -> bool {
        self.slots.pending.is_empty()
    }
}