Expand description
This is a Rust interface to Fizzy, a fast, deterministic, and pedantic WebAssembly interpreter.
§Examples
This is a generic example for parsing and instantiating a module, and executing a simple function with inputs and an output.
extern crate fizzy;
fn main() {
// This wasm binary exports a single sum(u32, u32) -> u32 function.
let wasm = [
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f,
0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03, 0x73, 0x75, 0x6d,
0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,
];
let module = fizzy::parse(&wasm).expect("parsing failed");
let mut instance = module.instantiate().expect("instantiation failed");
let result = instance
.execute(
"sum",
&[fizzy::TypedValue::U32(42), fizzy::TypedValue::U32(24)],
)
.expect("execution failed");
let result = result
.expect("return value expected")
.as_u32()
.expect("u32 expected as a return type");
assert_eq!(result, 66);
}
Structs§
- Execution
Result - The result of an execution.
- Instance
- An instance of a module.
- Module
- A parsed and validated WebAssembly 1.0 module.
Enums§
- Error
- The various kinds of errors, which can be returned by any of the interfaces.
- Typed
Value - A WebAssembly value i32/i64/f32/f64 with its type specified.
Functions§
- parse
- Parse and validate the input according to WebAssembly 1.0 rules.
- validate
- Parse and validate the input according to WebAssembly 1.0 rules. Returns true if the supplied input is valid.
Type Aliases§
- Value
- A WebAssembly value of i32/i64/f32/f64.