The wasmedge-sys crate defines a group of low-level Rust APIs for WasmEdge, a light-weight, high-performance, and extensible WebAssembly runtime for cloud-native, edge, and decentralized applications.
For developers, it is recommended that the APIs in wasmedge-sys
are used to construct high-level libraries, while wasmedge-sdk
(coming soon) is for building up business applications.
To use or build the wasmedge-sys
crate, the wasmedge-core
is required. The Build wasmedge-sys crate section of WasmEdge Docs gives the tips.
A quick-start example below is using wasmedge-sys
to run a WebAssembly module written with its WAT format (textual format):
```rust use wasmedgesys::{Vm, WasmValue}; use wasmedgetypes::wat2wasm;
fn main() -> Result<(), Box
// create a Vm instance
let mut vm = Vm::create(None, None)?;
// register the wasm bytes
let module_name = "extern-module";
vm.register_wasm_from_buffer(module_name, &wasm_bytes)?;
// run the exported function named "fib"
let func_name = "fib";
let result = vm.run_registered_function(module_name, func_name, [WasmValue::from_i32(5)])?;
assert_eq!(result.len(), 1);
assert_eq!(result[0].to_i32(), 8);
Ok(())
} ```