use crate::{MappedPageError, Pager};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PageId(pub u64);
#[repr(transparent)]
pub struct MappedPage([u8]);
impl PageId {
pub fn get<'a>(&self, pager: &'a Pager) -> Result<&'a MappedPage, MappedPageError> {
pager.get_page(*self)
}
pub fn get_mut<'a>(&self, pager: &'a mut Pager) -> Result<&'a mut MappedPage, MappedPageError> {
pager.get_page_mut(*self)
}
}
impl MappedPage {
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn as_bytes_mut(&mut self) -> &mut [u8] {
&mut self.0
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub(crate) unsafe fn from_slice(s: &[u8]) -> &Self {
unsafe { &*(s as *const [u8] as *const MappedPage) }
}
pub(crate) unsafe fn from_slice_mut(s: &mut [u8]) -> &mut Self {
unsafe { &mut *(s as *mut [u8] as *mut MappedPage) }
}
}