pub struct WasmPlugin { /* private fields */ }Expand description
A Plugin backed by a sandboxed WASM module.
Load a .wasm (or .wat, useful for testing) module with WasmPlugin::load,
map its business functions to implementation names with
with_function_map, then register it via
CliBuilder::register_plugin or the
convenience CliBuilder::register_wasm_plugin.
See the module-level documentation for the full ABI contract.
Implementations§
Source§impl WasmPlugin
impl WasmPlugin
Sourcepub fn load(path: &Path) -> Result<Self>
pub fn load(path: &Path) -> Result<Self>
Load a WASM module from disk and validate its mandatory exports.
Accepts both binary .wasm and text .wat modules (the latter is
primarily useful for tests and minimal fixtures).
§Errors
Returns WasmError::LoadFailed if the file cannot be read or fails
to compile/validate. Returns WasmError::FunctionNotFound if
memory, dcli_alloc, or dcli_dealloc is missing — these three
are mandatory regardless of which business functions are mapped
later.
§Example
use dynamic_cli::plugin::wasm::WasmPlugin;
use std::path::Path;
let plugin = WasmPlugin::load(Path::new("plugins/greet.wasm"))?;Sourcepub fn from_bytes(bytes: &[u8], origin: &Path) -> Result<Self>
pub fn from_bytes(bytes: &[u8], origin: &Path) -> Result<Self>
Sourcepub fn with_function_map(self, impl_name: &str, wasm_fn_name: &str) -> Self
pub fn with_function_map(self, impl_name: &str, wasm_fn_name: &str) -> Self
Map an implementation name to a WASM-exported business function.
The exported function name is chosen freely by the plugin author —
dynamic-cli imposes no naming convention beyond the four reserved
names (memory, dcli_alloc, dcli_dealloc, dcli_last_error_message).
Existence of wasm_fn_name in the module is verified at handler
construction time, in Plugin::handlers.
§Example
use dynamic_cli::plugin::wasm::WasmPlugin;
use std::path::Path;
let plugin = WasmPlugin::load(Path::new("plugins/greet.wasm"))?
.with_function_map("greet_hello", "say_hello");Sourcepub fn with_format(self, format: WasmSerializationFormat) -> Self
pub fn with_format(self, format: WasmSerializationFormat) -> Self
Set the serialization format used for argument exchange.
Defaults to WasmSerializationFormat::Yaml.
Sourcepub fn with_metadata(self, name: &str, version: &str, description: &str) -> Self
pub fn with_metadata(self, name: &str, version: &str, description: &str) -> Self
Set plugin metadata (name, version, description).
When not called, defaults are derived from the module’s file name
(name), "0.0.0" (version), and a generic description.
Trait Implementations§
Source§impl Plugin for WasmPlugin
impl Plugin for WasmPlugin
Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl !RefUnwindSafe for WasmPlugin
impl !UnwindSafe for WasmPlugin
impl Freeze for WasmPlugin
impl Send for WasmPlugin
impl Sync for WasmPlugin
impl Unpin for WasmPlugin
impl UnsafeUnpin for WasmPlugin
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
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