use std::{mem::MaybeUninit, ptr};
use crate::buffer::{self, storage};
unsafe impl<P: buffer::raw::Policy> buffer::raw::Source for storage::Owned<P> {}
unsafe impl<P: buffer::raw::Policy> buffer::raw::Source for &mut storage::Owned<P> {}
unsafe impl<P: buffer::raw::Policy> buffer::raw::Prefix for storage::Owned<P> {
fn prefix(&self) -> (*mut MaybeUninit<u8>, u32) {
let pointer = self
.allocation
.as_ref()
.map_or(ptr::NonNull::dangling().as_ptr(), |heap| {
heap.as_ptr().cast_mut()
});
(pointer, self.len)
}
}
unsafe impl<P: buffer::raw::Policy> buffer::raw::Exclusive for storage::Owned<P> {
fn as_mut_ptr(&mut self) -> *mut MaybeUninit<u8> {
buffer::raw::Prefix::prefix(self).0
}
fn len_mut(&mut self) -> &mut u32 {
&mut self.len
}
fn capacity(&self) -> u32 {
storage::Owned::capacity(self) as u32
}
}
unsafe impl buffer::raw::Source for storage::Exact {}