#[no_mangle]
pub extern "C" fn add_one(x: i32) -> i32 {
x + 1
}
#[no_mangle]
pub extern "C"
fn add_one(x: i32) -> i32
{
x + 1
}
fetch('../out/main.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes))
WebAssembly
.instantiateStreaming(fetch('../out/main.wasm'))
.then(instance => /* do something */);
instantiate(sourceBuffer, importObject);
instantiateStreaming(source, importObject);
const importObject = {
env: {
logResult(result) {
console.log(result);
},
}
}
...
WebAssembly.instantiate(bytes, importObject)
...
extern {
fn logResult(i: i32);
}
#[no_mangle]
pub extern "C" fn add_one(x: i32) {
unsafe {
logResult(x + 1);
}
}