I’ve been using the Rust programming language at work quite a lot recently, and really like it.
In this week’s issue of This Week in Rust, I saw that WebAssembly was now supported natively in rustc (previously it was supported via Emscripten).
WebAssembly is a binary executable format designed to give (near-)native performance of code embedded in webpages.
Although I don’t do web development as work, I do sometimes do it for side projects, and it’s always fun to try something new!
This then gives the same behavior as the simple add example, just with a lot more code – great!
Of course, the next step is to pass a string. This is a little more difficult, because strings aren’t a primitive type in WebAssembly, so there’s no convention for passing them.
Note that, in order to access the memory export, we also had to save a reference to the loaded module (in the “mod” variable).
This is all a bit long-winded, but I haven’t found a better way – any observations on how to do it better would be appreciated!