use core::{fmt, marker::PhantomData};
use super::Kernel;
use crate::utils::Init;
#[doc(include = "../common.md")]
pub struct Hunk<System> {
start: usize,
_phantom: PhantomData<System>,
}
impl<System> Init for Hunk<System> {
const INIT: Self = Self::from_offset(0);
}
impl<System: Kernel> fmt::Debug for Hunk<System> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Hunk({:p})", self.as_ptr())
}
}
impl<System> Clone for Hunk<System> {
fn clone(&self) -> Self {
*self
}
}
impl<System> Copy for Hunk<System> {}
impl<System> Hunk<System> {
#[doc(hidden)]
pub const fn from_offset(start: usize) -> Self {
Self {
start,
_phantom: PhantomData,
}
}
pub const fn offset(self) -> usize {
self.start
}
}
impl<System: Kernel> Hunk<System> {
#[inline]
pub fn as_ptr(self) -> *mut u8 {
System::hunk_pool_ptr().wrapping_add(self.start)
}
}