21 breaking releases

0.27.0 May 21, 2021
0.26.0 Apr 5, 2021
0.25.0 Mar 16, 2021
0.21.0 Nov 5, 2020
0.8.0 Nov 20, 2019

#49 in #aot

Download history 6/week @ 2022-04-20 212/week @ 2022-04-27 166/week @ 2022-05-04 351/week @ 2022-05-11 98/week @ 2022-05-18 100/week @ 2022-05-25 216/week @ 2022-06-01 52/week @ 2022-06-08 7/week @ 2022-06-15 33/week @ 2022-06-22 31/week @ 2022-06-29 5/week @ 2022-07-06 30/week @ 2022-07-13 48/week @ 2022-07-20 98/week @ 2022-07-27 79/week @ 2022-08-03

256 downloads per month

Apache-2.0 WITH LLVM-exception

1MB
12K SLoC

wasmtime-rust - Using WebAssembly from Rust

This crate is intended to be an example of how to load WebAssembly files from a native Rust application. You can always use wasmtime and its family of crates directly, but the purpose of this crate is to provide an ergonomic macro:

#[wasmtime_rust::wasmtime]
trait WasmMarkdown {
    fn render(&mut self, input: &str) -> String;
}

fn main() -> anyhow::Result<()> {
    let mut markdown = WasmMarkdown::load_file("markdown.wasm")?;
    println!("{}", markdown.render("# Hello, Rust!"));

    Ok(())
}

The wasmtime macro defined in the wasmtime-rust crate is placed on a trait which includes the set of functionality which a wasm module should export. In this case we're expecting one render function which takes and returns a string.

The macro expands to a struct with all of the methods on the trait (they must all be &mut self) and one function called load_file to actually instantiate the module.

Note that this macro is still in early stages of development, so error messages aren't great yet and all functionality isn't supported yet.

Missing features

Currently if the wasm module imports any symbols outside of the WASI namespace the module will not load. It's intended that support for this will be added soon though!

Dependencies

~19MB
~424K SLoC