o3 0.62.0

shared-nothing primitives
Documentation
use std::{num::NonZero, ptr};

use crate::buffer::{
    pool::{Span, owners},
    storage,
};

/// # Safety
/// `start..start + len` is initialized within the consumed span's retained
/// capacity, with no conflicting live loans. The span owns the range's slot edge.
pub(in crate::buffer::pool) unsafe fn into_shared<K: crate::buffer::raw::Backing, M, S>(
    span: Span<K, M, S>,
    start: usize,
    len: usize,
) -> storage::Shared<Option<owners::Edge<K, M>>> {
    let Some(len) = NonZero::new(len) else {
        return storage::Shared::empty(None);
    };
    // SAFETY: the original range admission and ownership are unchanged.
    unsafe { into_nonempty(span, start, len) }
}

/// # Safety
/// `start..start + len` is initialized within the consumed span's retained
/// capacity, with no conflicting live loans. The span owns the range's slot edge.
pub(in crate::buffer) unsafe fn into_nonempty<K: crate::buffer::raw::Backing, M, S>(
    span: Span<K, M, S>,
    start: usize,
    len: NonZero<usize>,
) -> storage::Shared<Option<owners::Edge<K, M>>> {
    // SAFETY: the consumed span retains this exact nonempty in-bounds range.
    let data = unsafe { span.slots.data(span.key).add(start) };
    // SAFETY: pool allocation data is non-null.
    let data = unsafe { ptr::NonNull::new_unchecked(data) };
    let edge = Some(owners::Edge::from(span));
    // SAFETY: edge retains the exact live slot containing this initialized
    // range and is installed atomically with its extent.
    unsafe { storage::raw::Extent::new(data, len.get()).bind(edge) }
}