pub struct PluginInstance { /* private fields */ }Expand description
A running WebAssembly plugin instance.
Holds the Wasmtime Store and Instance for a single plugin. All
calls happen in the context of this instance and consume its fuel budget.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let wasm_bytes: &[u8] = b"";
let runtime = PluginRuntime::new().unwrap();
let mut plugin = runtime.load(wasm_bytes, CapabilitySet::empty()).unwrap();
plugin.invoke("run").unwrap();Implementations§
Source§impl PluginInstance
impl PluginInstance
Sourcepub fn invoke(&mut self, name: &str) -> Result<(), PluginError>
pub fn invoke(&mut self, name: &str) -> Result<(), PluginError>
Invokes an exported function that takes no parameters and returns nothing.
§Errors
Returns PluginError::MissingExport if the export does not exist or
has the wrong signature, or any other plugin error if execution fails.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let runtime = PluginRuntime::new().unwrap();
let mut plugin = runtime.load(wasm_bytes, CapabilitySet::empty()).unwrap();
plugin.invoke("run").unwrap();Sourcepub fn invoke_typed<Args, Rets>(
&mut self,
name: &str,
args: Args,
) -> Result<Rets, PluginError>where
Args: WasmParams,
Rets: WasmResults,
pub fn invoke_typed<Args, Rets>(
&mut self,
name: &str,
args: Args,
) -> Result<Rets, PluginError>where
Args: WasmParams,
Rets: WasmResults,
Invokes an exported function with a statically checked WebAssembly signature.
§Errors
Returns PluginError::MissingExport if the export does not exist or
has a signature different from Args -> Rets, or any execution error
produced by the plugin.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let wasm_bytes: &[u8] = b"";
let runtime = PluginRuntime::new().unwrap();
let mut plugin = runtime.load(wasm_bytes, CapabilitySet::empty()).unwrap();
let result: i32 = plugin.invoke_typed("add_one", 41).unwrap();
assert_eq!(result, 42);Sourcepub fn drain_paint_commands(&mut self, f: impl FnMut(&PluginPaintCmd, &[u8]))
pub fn drain_paint_commands(&mut self, f: impl FnMut(&PluginPaintCmd, &[u8]))
Drains paint commands from this instance’s shared ring buffer.
The ring region lives inside guest-visible linear memory: either a
host-grown region of the guest’s exported memory, or the dedicated
martensite.ring_memory import. The guest produces commands by writing
PluginPaintCmd records plus the head/tail cursor header directly;
this call consumes and clears them. Does nothing when the plugin has no
ring region.
§Examples
use martensite_plugin::{CapabilitySet, PluginRuntime};
let wasm_bytes: &[u8] = b"";
let runtime = PluginRuntime::new().unwrap();
let mut plugin = runtime.load(wasm_bytes, CapabilitySet::empty()).unwrap();
plugin.drain_paint_commands(|cmd, payload| {
println!("cmd_type={}, {} bytes", cmd.cmd_type, payload.len());
});Sourcepub fn capabilities(&self) -> &CapabilitySet
pub fn capabilities(&self) -> &CapabilitySet
Returns a reference to the capability set active for this instance.
§Examples
use martensite_plugin::{Capability, CapabilitySet, PluginRuntime};
let wasm_bytes: &[u8] = b"";
let caps = CapabilitySet::builder().grant(Capability::Network).build();
let runtime = PluginRuntime::new().unwrap();
let plugin = runtime.load(wasm_bytes, caps).unwrap();
assert!(plugin.capabilities().contains(&Capability::Network));Auto Trait Implementations§
impl !RefUnwindSafe for PluginInstance
impl !Sync for PluginInstance
impl !UnwindSafe for PluginInstance
impl Freeze for PluginInstance
impl Send for PluginInstance
impl Unpin for PluginInstance
impl UnsafeUnpin for PluginInstance
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
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,
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,
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> ⓘ
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> ⓘ
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