o3 0.62.0

shared-nothing primitives
Documentation
use crate::buffer::storage::provided::Sealed;
use std::{cell, fmt::Debug, mem::MaybeUninit, num::NonZero};

/// Static storage layout for a provided registration.
pub trait Layout: Sealed + Debug + Unpin {
    type Slot;
    type Shared;
    fn empty() -> Self::Slot;
    /// # Safety
    /// This slot holds its admitted live projection.
    unsafe fn resident(slot: &Self::Slot, shared: &Self::Shared) -> u32;
}

impl Layout for () {
    type Slot = ();
    type Shared = NonZero<u32>;
    fn empty() {}
    unsafe fn resident(_: &(), shared: &Self::Shared) -> u32 {
        shared.get()
    }
}

impl Layout for cell::Cell<u32> {
    type Slot = cell::Cell<MaybeUninit<u32>>;
    type Shared = ();
    fn empty() -> Self::Slot {
        cell::Cell::new(MaybeUninit::uninit())
    }
    unsafe fn resident(slot: &Self::Slot, _: &()) -> u32 {
        // SAFETY: publication initialized this exact slot's admitted capacity.
        unsafe { slot.get().assume_init() }
    }
}