use std::mem::MaybeUninit;
use crate::buffer::{pool, raw, resident, storage};
pub unsafe trait Target: AsRef<[u8]> {
fn capacity(&self) -> usize;
fn truncate(&mut self, len: usize);
unsafe fn spare(&mut self) -> &mut [MaybeUninit<u8>];
unsafe fn complete(&mut self, amount: usize);
}
unsafe impl Target for storage::Owned<resident::Budget<'_>> {
fn capacity(&self) -> usize {
self.capacity()
}
fn truncate(&mut self, len: usize) {
self.truncate(len);
}
unsafe fn spare(&mut self) -> &mut [MaybeUninit<u8>] {
raw::Exclusive::spare_parts(self).1
}
unsafe fn complete(&mut self, amount: usize) {
*raw::Exclusive::len_mut(self) += amount as u32;
}
}
unsafe impl<K: raw::Backing, S: pool::state::State> Target for pool::Span<K, pool::Owned, S>
where
Self: raw::Exclusive,
{
fn capacity(&self) -> usize {
self.capacity().get() as usize
}
fn truncate(&mut self, len: usize) {
self.truncate(len);
}
unsafe fn spare(&mut self) -> &mut [MaybeUninit<u8>] {
raw::Exclusive::spare_parts(self).1
}
unsafe fn complete(&mut self, amount: usize) {
*raw::Exclusive::len_mut(self) += amount as u32;
}
}