implements PLN-0109
This commit is contained in:
@@ -1,27 +1,17 @@
|
||||
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, platform: None }
|
||||
pub fn new(platform: Option<&'a mut dyn RuntimePlatform>) -> Self {
|
||||
Self { platform }
|
||||
}
|
||||
|
||||
pub fn new_platform(platform: Option<&'a mut dyn RuntimePlatform>) -> Self {
|
||||
Self { hw: None, platform }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn require_hw(&mut self) -> Result<&mut dyn HardwareBridge, VmFault> {
|
||||
match &mut self.hw {
|
||||
Some(hw) => Ok(*hw),
|
||||
None => Err(VmFault::Unavailable),
|
||||
}
|
||||
Self::new(platform)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user