use crate::{
Result,
arch::NativeArch,
image::ModuleHandle,
input::ElfReader,
linker::{DependencyRequest, RootRequest},
relocation::RelocationArch,
};
use alloc::{boxed::Box, vec::Vec};
pub enum ResolvedKey<'cfg, K, Arch: RelocationArch = NativeArch> {
Existing(K),
Load {
key: K,
reader: Box<dyn ElfReader + 'cfg>,
},
Synthetic {
key: K,
module: ModuleHandle<Arch>,
deps: Vec<ResolvedKey<'cfg, K, Arch>>,
},
}
impl<'cfg, K, Arch: RelocationArch> ResolvedKey<'cfg, K, Arch> {
#[inline]
pub fn existing(key: K) -> Self {
Self::Existing(key)
}
#[inline]
pub fn load(key: K, reader: impl ElfReader + 'cfg) -> Self {
Self::Load {
key,
reader: Box::new(reader),
}
}
#[inline]
pub fn synthetic(
key: K,
module: impl Into<ModuleHandle<Arch>>,
deps: impl Into<Vec<ResolvedKey<'cfg, K, Arch>>>,
) -> Self {
Self::Synthetic {
key,
module: module.into(),
deps: deps.into(),
}
}
}
pub trait KeyResolver<'cfg, K: Clone, Arch: RelocationArch = NativeArch> {
fn load_root(&mut self, req: &RootRequest<'_, K>) -> Result<ResolvedKey<'cfg, K, Arch>>;
fn resolve_dependency(
&mut self,
req: &DependencyRequest<'_, K>,
) -> Result<ResolvedKey<'cfg, K, Arch>>;
}