Crate wasm_plugin_host[−][src]
A low-ish level tool for easily hosting WASM based plugins.
The goal of wasm_plugin is to make communicating across the host-plugin boundary as simple and idiomatic as possible while being unopinionated about how you actually use the plugin.
Plugins should be written using wasm_plugin_guest
Loading a plugin is as simple as reading the .wasm file off disk.
let mut plugin = WasmPlugin::load("path/to/plugin.wasm")?;
Calling functions exported by the plugin takes one of two forms. Either the function takes no arguments and returns a single serde deserializable value:
let response: ResultType = plugin.call_function("function_name")?;
Or it takes a single serializable argument and returns a single result:
let message = Message::default(); let response: ResultType = plugin.call_function_with_argument("function_name", &message)?;
If the inject_getrandom feature is selected then the host’s getrandom
will be injected into the plugin which allows rand to be used in the
plugin. inject_getrandom is selected by default.
Currently serialization uses either bincode or json, selected by feature:
serialize_bincode: Uses serde and bincode. It is selected by default.
serialize_json: Uses serde and serde_json.
`serialize_nanoserde_json’: Uses nanoserde.
Bincode is likely the best choice if all plugins the system uses will be written in Rust. Json is useful if a mix or languages will be used.
Limitations
There is no reflection so you must know up front which functions a plugin exports and their signatures.
Modules
| errors | |
| serialization |
Structs
| WasmPlugin | A loaded plugin |
| WasmPluginBuilder | Constructs a WasmPlugin |
Enums
| Extern | An |
Traits
| HostFunction | The |
| ImportableFn | A marker trait for Fn types who’s arguments and return type can be serialized and are thus safe to import into a plugin; |