pub struct PluginRuntime { /* private fields */ }Expand description
Preconfigured Wasmtime runtime environment for loading plugins.
The engine is shared across instances; the linker is configured once with the WASIp1 imports and Martensite host functions.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let runtime = PluginRuntime::new().unwrap();
// The empty capability set gives the plugin no host access.
let _ = runtime.load(b"\0asm\x01\0\0\0", CapabilitySet::empty());
// (Loading a real wasm module would succeed; a minimal header is shown here.)Implementations§
Source§impl PluginRuntime
impl PluginRuntime
Sourcepub fn new() -> Result<Self, PluginError>
pub fn new() -> Result<Self, PluginError>
Sourcepub fn with_fuel_budget(fuel_budget: u64) -> Result<Self, PluginError>
pub fn with_fuel_budget(fuel_budget: u64) -> Result<Self, PluginError>
Sourcepub fn engine(&self) -> &Engine
pub fn engine(&self) -> &Engine
Returns the Wasmtime engine used by this runtime.
Epoch interruption is configured for every plugin store. The host must
call Engine::increment_epoch on this engine on a 5 ms cadence to
enforce the wall-clock deadline in addition to the fuel budget.
§Examples
use martensite_plugin::PluginRuntime;
let runtime = PluginRuntime::new().unwrap();
let _engine = runtime.engine();Sourcepub fn load(
&self,
wasm_bytes: &[u8],
caps: CapabilitySet,
) -> Result<PluginInstance, PluginError>
pub fn load( &self, wasm_bytes: &[u8], caps: CapabilitySet, ) -> Result<PluginInstance, PluginError>
Loads and instantiates a plugin with the given capability set.
The returned PluginInstance is independent from the runtime and can
be invoked repeatedly until its fuel budget is exhausted.
§Errors
Returns an error if compilation, instantiation, or fuel setup fails.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let runtime = PluginRuntime::new().unwrap();
// Loading invalid bytes returns an error.
assert!(runtime.load(b"not wasm", CapabilitySet::empty()).is_err());Auto Trait Implementations§
impl !RefUnwindSafe for PluginRuntime
impl !UnwindSafe for PluginRuntime
impl Freeze for PluginRuntime
impl Send for PluginRuntime
impl Sync for PluginRuntime
impl Unpin for PluginRuntime
impl UnsafeUnpin for PluginRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
Set the “status” flags for the
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more