use super::{LinkPassPlan, ReorderAccess};
use crate::{
linker::scan::{ArenaDescriptor, ArenaId, ArenaUsage},
relocation::RelocationArch,
};
use core::marker::PhantomData;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Arena<'plan> {
id: ArenaId,
marker: PhantomData<fn(&'plan ())>,
}
impl<'plan> Arena<'plan> {
#[inline]
pub(super) const fn new(id: ArenaId) -> Self {
Self {
id,
marker: PhantomData,
}
}
#[inline]
pub(in crate::linker) const fn id(self) -> ArenaId {
self.id
}
}
impl<'scope> Arena<'scope> {
#[inline]
pub fn descriptor<'borrow, K, S, Arch>(
self,
plan: &'borrow LinkPassPlan<'scope, K, S, Arch>,
) -> &'borrow ArenaDescriptor
where
K: Clone + Ord,
S: ReorderAccess,
Arch: RelocationArch,
{
plan.plan.memory_layout().arena(self.id)
}
#[inline]
pub fn usage<K, S, Arch>(self, plan: &LinkPassPlan<'scope, K, S, Arch>) -> ArenaUsage
where
K: Clone + Ord,
S: ReorderAccess,
Arch: RelocationArch,
{
plan.plan.memory_layout().usage(self.id)
}
}