Best way to do rust/wasm32 + js integration?

  1. Here, by "integration" I am referring to JS land being able to: (1) read/write fields of Rust structs, (2) calling functions of traits.

  2. "solutions" I am aware of:

  • manually exposing callbacks by having Rust use stdweb::js! macro

  • serde_json for serialize/deserialize methods

  • capn proto: (not sure):can *.capnp files generate JS API ?

  1. What I would like to be able to do:
  • tag struct or func with "#[derive(JSAPI)] then be able to either (1) read/write fields for structs and (2) for functions, call the function
  1. The goal is to, for a webapp, write lots of high performance primitives in Rust, and do scripting in JS.

Take a look at wasm-bindgen.
And also read the rust+wasm book, which introduces this and other tools to get started.

There's also wasm-pack which is a nice wrapper around wasm-bindgen.