29 lines
734 B
Rust
29 lines
734 B
Rust
use crate::platform::RuntimePlatform;
|
|
use crate::vm_fault::VmFault;
|
|
|
|
pub struct HostContext<'a> {
|
|
pub platform: Option<&'a mut dyn RuntimePlatform>,
|
|
}
|
|
|
|
impl<'a> HostContext<'a> {
|
|
pub fn new(platform: Option<&'a mut dyn RuntimePlatform>) -> Self {
|
|
Self { platform }
|
|
}
|
|
|
|
pub fn new_platform(platform: Option<&'a mut dyn RuntimePlatform>) -> Self {
|
|
Self::new(platform)
|
|
}
|
|
|
|
#[inline]
|
|
pub fn require_platform(&mut self) -> Result<&mut dyn RuntimePlatform, VmFault> {
|
|
match &mut self.platform {
|
|
Some(platform) => Ok(*platform),
|
|
None => Err(VmFault::Unavailable),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait HostContextProvider {
|
|
fn make_ctx(&'_ mut self) -> HostContext<'_>;
|
|
}
|