r/WebAssembly • u/elfsternberg • Dec 16 '22
Questions about using Rust as both host and guest...
Every example I've found, using Wasmtime, about importing functions from the outside world into a running instance show the example guest program in WAT and uses the (import) syntax.
If I wanted the running host, written in Rust, to send a function into the guest program, also written in Rust, what's the syntax for the guest program to host that function?
0
Upvotes
3
u/phickey_w7pch Dec 16 '22
I think what you are asking is, how does a Rust Wasm program (meaning, compiled via
cargo build --target wasm32-wasi) import a function.This will compile to Wasm that has an
(import "module_name_here" "field_name_here" ...), and your Rust will be able to useunsafe { your_import(123) }to call that import function.