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),
};
let bytes = unsafe { slice::from_raw_parts_mut(base, 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());
let heap = unsafe { ptr::read(crate::mem::raw::initialized(&owner.allocation)) };
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();
Self(unsafe { pool::raw::into_nonempty(source.into_storage(), 0, len) }.into())
}
}