In the previous article, we showed you how to compile a Rust program into a WebAssembly bytecode file. The easiest way to run a WebAssembly bytecode file is to simply load it into a web browser. Most modern web browsers already support WebAssembly.
const response = await fetch('my_project_name.wasm'); const buffer = await response.arrayBuffer(); const module = await WebAssembly.compile(buffer); const instance = await WebAssembly.instantiate(module); const exports = instance.exports; const triple = exports.triple;
in WebAssembly and triple your input number. The code below returns number
Of course, you can just easily load Rust compiled WebAssembly functions from your web page. Check out a full example here.