[−][src]Crate wasmer_runtime
Wasmer-runtime is a library that makes embedding WebAssembly in your application easy, efficient, and safe.
How to use Wasmer-Runtime
The easiest way is to use the instantiate function to create an Instance.
Then you can use call or func and then call to call an exported function safely.
Example
Given this WebAssembly:
(module
(type $t0 (func (param i32) (result i32)))
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
get_local $p0
i32.const 1
i32.add))
compiled into wasm bytecode, we can call the exported add_one function:
static WASM: &'static [u8] = &[ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0b, 0x01, 0x07, 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x0b, 0x00, 0x1a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x01, 0x0a, 0x01, 0x00, 0x07, 0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x02, 0x07, 0x01, 0x00, 0x01, 0x00, 0x02, 0x70, 0x30, ]; use wasmer_runtime::{ instantiate, Value, imports, Func, }; fn main() -> Result<(), Box<dyn std::error::Error>> { let import_object = imports! {}; let mut instance = instantiate(WASM, &import_object)?; let add_one: Func<i32, i32> = instance.exports.get("add_one")?; let value = add_one.call(42)?; assert_eq!(value, 43); Ok(()) }
Modules
| cache | The cache module provides the common data structures used by compiler backends to allow serializing compiled wasm code to a binary format. The binary format can be persisted, and loaded to allow skipping compilation and fast startup. |
| error | The error module contains the data structures and helper functions used to implement errors that are produced and returned from the wasmer runtime. |
| memory | The memory module contains the implementation data structures and helper functions used to manipulate and access wasm memory. |
| types | Types used in the Wasm runtime and conversion functions. |
| units | Various unit types. |
| wasm | Various types exposed by the Wasmer Runtime. |
Macros
| func | Helper macro to create a new |
| imports | Generate an |
Structs
| Array | The |
| Ctx | The context of the currently running WebAssembly instance. |
| DynFunc | Represents a type-erased function provided by either the host or the WebAssembly program. |
| DynamicFunc | Represents a type-erased function provided by either the host or the WebAssembly program. |
| Func | Represents a function that can be used by WebAssembly. |
| Global | A handle to a Wasm Global |
| ImportObject | All of the import data used when instantiating. |
| Instance | An instantiated WebAssembly module. |
| Item | The |
| Memory | A Wasm linear memory. |
| Module | A compiled WebAssembly module. |
| Table | Container with a descriptor and a reference to a table storage. |
| WasmPtr | A zero-cost type that represents a pointer to something in Wasm linear memory. |
Enums
| Backend | Enum used to select which compiler should be used to generate code. |
| Export | An |
| InstantiateError | |
| RuntimeExport | The value of an export passed from one instance to another. |
Constants
| VERSION |
Traits
| LikeNamespace | The |
Functions
| compile | Compile WebAssembly binary code into a |
| compile_with | Compile a |
| instantiate | |
| load_cache_with | Creates a new module from the given cache |
| validate | Perform validation as defined by the
WebAssembly specification. Returns |
| wat2wasm | Parses in-memory bytes as either the WebAssembly Text format, or a binary WebAssembly module. |
Type Definitions
| Value | WebAssembly computations manipulate values of basic value types: |