o3 0.62.0

shared-nothing primitives
Documentation
use std::{mem::ManuallyDrop, ptr, slice};

use crate::buffer::{self, pool, storage, write};

impl<'a, P: buffer::raw::Policy> From<&'a mut storage::Owned<P>>
    for write::raw::Slice<'a, &'a mut u32, u32>
{
    fn from(owner: &'a mut storage::Owned<P>) -> Self {
        let (base, capacity) = match &mut owner.allocation {
            Some(heap) => (heap.as_mut_ptr(), heap.capacity().get() as usize),
            None => (ptr::NonNull::dangling().as_ptr(), 0),
        };
        // SAFETY: this unique heap retains its complete range and disjoint initialized count.
        let bytes = unsafe { slice::from_raw_parts_mut(base, capacity) };
        // SAFETY: the initialized prefix fits this allocation's admitted u32 capacity.
        unsafe { write::raw::Slice::from_parts(bytes, &mut owner.len) }
    }
}

impl From<storage::NonEmpty<storage::Owned>> for storage::NonEmpty<storage::Shared> {
    fn from(source: storage::NonEmpty<storage::Owned>) -> Self {
        let owner = ManuallyDrop::new(source.into_storage());
        // SAFETY: this retained positive initialized length requires exactly one live heap.
        let heap = unsafe { ptr::read(crate::mem::raw::initialized(&owner.allocation)) };
        // SAFETY: both the edge and its initialized prefix transfer together exactly once.
        Self(unsafe { buffer::raw::Header::into_range(heap.into_shared(), 0, owner.len) }.into())
    }
}

impl From<storage::NonEmpty<pool::Span>> for storage::NonEmpty<storage::Shared> {
    fn from(source: storage::NonEmpty<pool::Span>) -> Self {
        let len = source.len();
        // SAFETY: the original span retains this admitted positive prefix.
        Self(unsafe { pool::raw::into_nonempty(source.into_storage(), 0, len) }.into())
    }
}