implements PLN-0104
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
use crate::hardware_bridge::HardwareBridge;
|
||||
use crate::platform::RuntimePlatform;
|
||||
use crate::vm_fault::VmFault;
|
||||
|
||||
pub struct HostContext<'a> {
|
||||
pub hw: Option<&'a mut dyn HardwareBridge>,
|
||||
pub platform: Option<&'a mut dyn RuntimePlatform>,
|
||||
}
|
||||
|
||||
impl<'a> HostContext<'a> {
|
||||
pub fn new(hw: Option<&'a mut dyn HardwareBridge>) -> Self {
|
||||
Self { hw }
|
||||
Self { hw, platform: None }
|
||||
}
|
||||
|
||||
pub fn new_platform(platform: Option<&'a mut dyn RuntimePlatform>) -> Self {
|
||||
Self { hw: None, platform }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -17,6 +23,14 @@ impl<'a> HostContext<'a> {
|
||||
None => Err(VmFault::Unavailable),
|
||||
}
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
||||
Reference in New Issue
Block a user