use std::{cell, mem::size_of, ptr};
use crate::{
buffer,
buffer::storage::{provided::arena, regions},
};
#[derive(Debug)]
pub struct Owner<'d, L: arena::Layout = cell::Cell<u32>> {
pub(super) entry: ptr::NonNull<arena::Entry<'d, L>>,
}
const _: () = assert!(size_of::<Owner<'static>>() == size_of::<usize>());
impl<L: arena::Layout> regions::End for Owner<'_, L> {
const EMPTY: Option<Self> = None;
}
impl<L: arena::Layout> buffer::Residency for Owner<'_, L> {
fn resident(&self) -> usize {
unsafe { self.entry.as_ref().capacity() as usize }
}
}
impl<L: arena::Layout> Drop for Owner<'_, L> {
fn drop(&mut self) {
unsafe { arena::Entry::release(self) };
}
}
impl<L: arena::Layout> buffer::Residency for &Owner<'_, L> {
fn resident(&self) -> usize {
(**self).resident()
}
}