o3 0.62.0

shared-nothing primitives
Documentation
use crate::{
    buffer::{
        self,
        storage::{provided, range},
    },
    mem,
};
use std::{cell, marker, ptr};

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

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

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

impl<L: provided::raw::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: provided::raw::Layout> Drop for Owner<'_, L> {
    fn drop(&mut self) {
        // SAFETY: Drop consumes this owner's sole external edge exactly once.
        let entry = unsafe { self.entry.as_ref() };
        if mem::raw::Edge::is_empty(entry) {
            // SAFETY: the expired external edge was the last edge for its domain.
            unsafe { entry.domain.as_ref() }
                .returned
                .finish(provided::raw::Ready {
                    entry: self.entry,
                    scope: marker::PhantomData,
                });
        } else {
            entry.state.set(provided::raw::Phase::ReturnOnLastAccount);
        }
    }
}

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