o3 0.61.0

shared-nothing primitives
Documentation
use std::{cell, mem::size_of, ptr};

use crate::{
    buffer,
    buffer::storage::{provided::arena, regions},
};

/// One live external edge branded by its arena allocation.
#[derive(Debug)]
pub struct Owner<'d, L: arena::Layout = cell::Cell<u32>> {
    pub(super) entry: ptr::NonNull<arena::Entry<'d, L>>,
}

const _: () = assert!(size_of::<Owner<'static>>() == size_of::<usize>());

impl<L: arena::Layout> regions::End for Owner<'_, L> {
    const EMPTY: Option<Self> = None;
}

impl<L: arena::Layout> buffer::Residency for Owner<'_, L> {
    fn resident(&self) -> usize {
        // SAFETY: the external edge retains the slot and its admitted resident ceiling.
        unsafe { self.entry.as_ref().capacity() as usize }
    }
}

impl<L: arena::Layout> Drop for Owner<'_, L> {
    fn drop(&mut self) {
        // SAFETY: Drop consumes this owner's sole live external edge exactly once.
        unsafe { arena::Entry::release(self) };
    }
}

impl<L: arena::Layout> buffer::Residency for &Owner<'_, L> {
    fn resident(&self) -> usize {
        (**self).resident()
    }
}