use crate::*;
use core::fmt;
use core::mem::{MaybeUninit, forget};
#[repr(transparent)]
pub struct Page<H, T>(PageRef<H, T>);
impl<H, T> Page<H, T> {
pub fn new(header: H, items: u32) -> Self { Page(PageRef::new(header, items)) }
#[inline(always)]
pub fn capacity(&self) -> u32 { unsafe { self.0.capacity() } }
#[inline(always)]
pub fn header(&self) -> &H { unsafe { self.0.header() } }
#[inline(always)]
pub fn header_mut(&mut self) -> &mut H { unsafe { self.0.header_mut() } }
#[inline(always)]
pub fn data(&self) -> *mut MaybeUninit<T> { unsafe { self.0.data() } }
#[inline(always)]
pub fn layout(&self) -> PageLayout<H, T> { PageLayout::with_capacity(self.0.desc().items) }
#[inline(always)]
pub unsafe fn from_uninit(raw_ptr: *mut u8, header: H, layout: PageLayout<H, T>) -> Self {
Page(PageRef::from_uninit(raw_ptr, header, layout))
}
pub unsafe fn from_ref(page_ref: PageRef<H, T>) -> Self { Page(page_ref) }
#[inline(always)]
pub fn to_ref(self) -> PageRef<H, T> {
let r = self.0;
forget(self); r
}
}
unsafe impl<H: Send, T: Send> Send for Page<H, T> {}
unsafe impl<H: Sync, T: Sync> Sync for Page<H, T> {}
impl<H, T> fmt::Debug for Page<H, T> {
#[inline(always)]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "Page[{}]", self.capacity())
}
}
impl<H, T> Drop for Page<H, T> {
#[inline(always)] fn drop(&mut self) { unsafe { PageRef::drop(self.0) } }
}