use crate::{VmFlags, VmMeta, PPN};
use core::{fmt, marker::PhantomData};
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct Pte<Meta: VmMeta>(pub usize, pub(crate) PhantomData<Meta>);
impl<Meta: VmMeta> Pte<Meta> {
pub const ZERO: Self = Self(0, PhantomData);
#[inline]
pub fn ppn(self) -> PPN<Meta> {
Meta::ppn(self.0)
}
#[inline]
pub fn is_leaf(self) -> bool {
Meta::is_leaf(self.0)
}
#[inline]
pub fn is_huge(self, level: usize) -> bool {
Meta::is_huge(self.0, level)
}
#[inline]
pub fn is_valid(self) -> bool {
Meta::is_valid(self.0)
}
#[inline]
pub fn flags(mut self) -> VmFlags<Meta> {
Meta::clear_ppn(&mut self.0);
unsafe { VmFlags::from_raw(self.0) }
}
}
impl<Meta: VmMeta> fmt::Debug for Pte<Meta> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Pte(")?;
self.0.fmt(f)?;
write!(f, ")")
}
}