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

Function main

examples/linking.rs:26–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24"#;
25
26fn main() -> Result<()> {
27 let wasm_add = wat::parse_str(WASM_ADD).expect("failed to parse wat");
28 let wasm_import = wat::parse_str(WASM_IMPORT).expect("failed to parse wat");
29
30 let add_module = tinywasm::parse_bytes(&wasm_add)?;
31 let import_module = tinywasm::parse_bytes(&wasm_import)?;
32
33 let mut store = Store::default();
34
35 // Instantiate the `add` module.
36 let add_instance = ModuleInstance::instantiate(&mut store, &add_module, None)?;
37
38 // Link the `adder` namespace to the `add` module's instance.
39 let mut imports = tinywasm::Imports::new();
40 imports.link_module("adder", add_instance)?;
41
42 // Instantiate the `import` module with the linked imports.
43 let import_instance = ModuleInstance::instantiate(&mut store, &import_module, Some(imports))?;
44
45 // Call the `main` function, which uses the imported `add` function.
46 let main = import_instance.func::<(), i32>(&store, "main")?;
47 assert_eq!(main.call(&mut store, ())?, 3);
48
49 Ok(())
50}

Callers

nothing calls this directly

Calls 2

parse_bytesFunction · 0.85
link_moduleMethod · 0.80

Tested by

no test coverage detected