o3 0.59.0

shared-nothing primitives
Documentation
use crate::depot::arena::linked::slots;
pub(in crate::buffer::segments) mod cursor;
pub(in crate::buffer::segments) mod iter;

use crate::buffer::{self, segments, segments::handles::Descriptor};

/// The live topology and byte extent borrowed from one nonempty owner.
pub(in crate::buffer::segments) enum Occupied<'a, T> {
    Single(slots::Index, &'a buffer::storage::NonEmpty<T>),
    Multi(&'a Descriptor),
}

impl<T> Occupied<'_, T> {
    pub(super) fn head(&self) -> slots::Index {
        match self {
            Self::Single(index, _) => *index,
            Self::Multi(desc) => desc.links.head_raw(),
        }
    }

    pub(super) fn count(&self) -> segments::Count {
        match self {
            Self::Single(..) => segments::Count::ONE,
            Self::Multi(desc) => segments::Count::new(desc.totals.count.get()),
        }
    }
}

impl<T: buffer::raw::Segment> Occupied<'_, T> {
    pub(super) fn len(&self) -> usize {
        match self {
            Self::Single(_, item) => item.len().get(),
            Self::Multi(desc) => desc.totals.len,
        }
    }

    pub(super) fn resident(&self) -> usize {
        match self {
            Self::Single(_, item) => buffer::Residency::resident(*item),
            Self::Multi(desc) => desc.totals.resident,
        }
    }
}