With the new wasm32-unknown-unknown
target being available in rustc, I made a simple POC library for easily importing Rust code from Javascript (both node.js and browsers). There are other similar libraries using Emscripten that served as inspiration but I tried to keep this one quite a bit simpler in comparison.
Some tl;dr example Javascript (ES6) code:
import loadRustlib from './path/to/rustlib/src/lib.rs'
loadRustlib().then(result => {
// This is a normal #[no_mangle] Rust function: fn add(i32, i32) -> i32
const add = result.instance.exports['add'];
console.log('return value was', add(2, 3));
});
I would love some feedback on the code: https://github.com/dflemstr/rust-native-wasm-loader
See published documentation on NPM: rust-native-wasm-loader - npm