mirror of
https://github.com/encounter/wasmtime.git
synced 2026-03-30 11:42:15 -07:00
9ce3ffe15e
* Update some CI dependencies * Update to the latest nightly toolchain * Update mdbook * Update QEMU for cross-compiled testing * Update `cargo nextest` for usage with MIRI prtest:full * Remove lots of unnecessary imports * Downgrade qemu as 8.2.1 seems to segfault * Remove more imports * Remove unused winch trait method * Fix warnings about unused trait methods * More unused imports * More unused imports
22 lines
750 B
Rust
22 lines
750 B
Rust
//! Example of instantiating of the WebAssembly module and invoking its exported
|
|
//! function.
|
|
|
|
// You can execute this example with `cargo run --example gcd`
|
|
|
|
use wasmtime::*;
|
|
|
|
fn main() -> Result<()> {
|
|
// Load our WebAssembly (parsed WAT in our case), and then load it into a
|
|
// `Module` which is attached to a `Store` cache. After we've got that we
|
|
// can instantiate it.
|
|
let mut store = Store::<()>::default();
|
|
let module = Module::from_file(store.engine(), "examples/gcd.wat")?;
|
|
let instance = Instance::new(&mut store, &module, &[])?;
|
|
|
|
// Invoke `gcd` export
|
|
let gcd = instance.get_typed_func::<(i32, i32), i32>(&mut store, "gcd")?;
|
|
|
|
println!("gcd(6, 27) = {}", gcd.call(&mut store, (6, 27))?);
|
|
Ok(())
|
|
}
|