o3 0.3.0

shared-nothing primitives
Documentation
use std::mem::MaybeUninit;

mod heap;
mod pin_cell_slab;
mod pin_slab;
mod queue;
mod slab;
mod table;

pub use heap::{IndexedMinHeap, IndexedMinHeapVacantEntry};
pub use pin_cell_slab::{PinCellSlab, PinCellSlabOccupiedEntry, PinCellSlabVacantEntry};
pub use pin_slab::{FixedPinSlab, FixedPinSlabOccupiedEntry, PinSlab, PinSlabOccupiedEntry};
pub use queue::{CellQueue, FixedQueue, FixedQueueVacantEntry, SlotQueue, SlotQueueVacantEntry};
pub use slab::{CellSlab, Slab, SlabGeneration, SlabKey, SlabKeyParts, SlabVacantEntry};
pub use table::FixedHashTable;

pub(crate) mod index {
    pub trait Sealed {}
}

#[doc(hidden)]
pub trait IndexKey: index::Sealed + Copy + Eq {
    fn index(self) -> usize;
}

impl IndexKey for usize {
    fn index(self) -> usize {
        self
    }
}

impl index::Sealed for usize {}

pub(crate) struct Storage;

impl Storage {
    pub(crate) fn uninit_boxed_slice<T>(len: usize) -> Box<[MaybeUninit<T>]> {
        Box::<[T]>::new_uninit_slice(len)
    }
}

pub(crate) struct ClearGuard<'a, T: ?Sized> {
    value: &'a mut T,
    clear: fn(&mut T),
    armed: bool,
}

impl<'a, T: ?Sized> ClearGuard<'a, T> {
    pub(crate) fn run(value: &'a mut T, clear: fn(&mut T)) {
        let mut guard = Self {
            value,
            clear,
            armed: true,
        };
        (guard.clear)(guard.value);
        guard.armed = false;
    }
}

impl<T: ?Sized> Drop for ClearGuard<'_, T> {
    fn drop(&mut self) {
        if self.armed {
            (self.clear)(self.value);
        }
    }
}