Skip to main content

WasmPlugin

Struct WasmPlugin 

Source
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

Source

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"))?;
Source

pub fn from_bytes(bytes: &[u8], origin: &Path) -> Result<Self>

Load a WASM module from raw bytes (binary .wasm or text .wat).

Used internally by load. Exposed for tests and for embedding scenarios where the module bytes are not stored on disk (e.g. fetched over the network).

Validates the same mandatory exports as load.

Source

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");
Source

pub fn with_format(self, format: WasmSerializationFormat) -> Self

Set the serialization format used for argument exchange.

Defaults to WasmSerializationFormat::Yaml.

Source

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

Source§

fn name(&self) -> &str

Short identifier for this plugin (e.g. "system", "greet").
Source§

fn version(&self) -> &str

Semantic version string (e.g. "1.0.0").
Source§

fn description(&self) -> &str

Human-readable description of what this plugin provides.
Source§

fn handlers(&self) -> Vec<(String, Box<dyn CommandHandler>)>

Returns the handlers this plugin contributes. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.