3 ms·
So, to take a few steps back, maybe you know some of this: First off, you write some wasm. You export some functions from the wasm. How you do this is up to yo
by steveklabnik 7y ago
So, to take a few steps back, maybe you know some of this:
First off, you write some wasm. You export some functions from the wasm. How you do this is up to your Rust code. wasm-bindgen would be the low-level details here.
Then, in your worker, you import the wasm. This shouldn't change from the templates, really. What signatures the imported functions have depends on how you exported them.
There's no inherent restrictions about what you can call, it's about knowing what you've exported and then calling them with the appropriate stuff.
So for example, https://github.com/jRiest/the-best-goats https://github.com/jRiest/the-best-goats is a little Rust wasm app. This app was built before wrangler existed, so it's got some strangeness, but it does work. https://github.com/jRiest/the-best-goats/blob/master/src/lib.rs#L518 https://github.com/jRiest/the-best-goats/blob/master/src/lib... is the main. I am not entirely sure how jake did this, but it looks like he compiled it to wasm, and then added https://github.com/jRiest/the-best-goats/blob/master/index.js#L737-L749 https://github.com/jRiest/the-best-goats/blob/master/index.j... at the bottom. Wrangler would make this a bit easier, of course. Regardless, you can see how these lines, which are the standard Worker entry point, calls into the main defined in wasm.
Does that help at all? It is certainly true that this is not as well documented as it could be. Lots of work still to do.