MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / main

Function main

examples/archive.rs:13–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11"#;
12
13fn main() -> Result<()> {
14 let wasm = wat::parse_str(WASM).expect("Failed to parse WAT");
15 let module = Parser::default().parse_module_bytes(wasm)?;
16 let twasm = module.serialize_twasm()?;
17
18 // Now, you could e.g. write `twasm` to a file called `add.twasm`
19 // and load it later in a different program.
20
21 let module = Module::try_from_twasm(&twasm)?;
22 let mut store = Store::default();
23 let instance = ModuleInstance::instantiate(&mut store, &module, None)?;
24 let add = instance.func::<(i32, i32), i32>(&store, "add")?;
25
26 assert_eq!(add.call(&mut store, (1, 2))?, 3);
27
28 Ok(())
29}

Callers

nothing calls this directly

Calls 2

parse_module_bytesMethod · 0.80
serialize_twasmMethod · 0.80

Tested by

no test coverage detected