This commit adds a `wasmtime-rust` crate to the `misc` folder next to the previously added Python extension. The intention is that this showcases loading a WebAssembly file natively in Rust and how with an attribute macro it can feel lightweight in terms of boilerplate. The macro itself is pretty non-featureful today beyond the bare bones to get anything working, but there's all sorts of possibilities like JIT-compiled entry stubs we could eventually do with all the type information!
14 lines
292 B
Rust
14 lines
292 B
Rust
use wasmtime_rust::wasmtime;
|
|
|
|
#[wasmtime]
|
|
trait WasmMarkdown {
|
|
fn render(&mut self, input: &str) -> String;
|
|
}
|
|
|
|
fn main() -> Result<(), failure::Error> {
|
|
let mut markdown = WasmMarkdown::load_file("markdown.wasm")?;
|
|
println!("{}", markdown.render("# Hello, Rust!"));
|
|
|
|
Ok(())
|
|
}
|