I was following the tutorial on making a WASM application with Rust. I decided on not using a bundler, but I stumbled upon a question. When using a bundler, to access WASM's memory, I can simply import { memory } from "<package>/<package>_bg"
, but without it, I can't make it work. What I'm doing:
import init , * as wasm from "./wasm/inner.js";
async function run() {
await init();
window.wasm = wasm;
wasm.debug_mode();
}
run();
This code works, and I can call Rust's functions easily. The problem is accessing WASM's memory. How do I get a reference to it, or something? Is it even possible? I stumbled upon the possibility of doing let wasm = await init();
, but the methods inside this object don't work, neither does the memory
object inside of it.
Thanks in advance!
You do not need to import memory. You can access memory through
let wasm = await init();
. E.g.Note: I am also learning wasm+rust without npm so my code style may be incorrect e.g.
my_inner
. I have been importing functions viaimport { function_name } from ...
.I found this information from this tutorial covering using rust+wasm without npm: https://lionturkey.github.io/posts/rustwasm/rustwasm.html