Replies: 3 comments
-
Yup, WebAssembly doesn't work this way. https://rustwasm.github.io/docs/wasm-bindgen/contributing/design/rust-type-conversions.html |
Beta Was this translation helpful? Give feedback.
-
|
Thank you very much for the help! I'm trying to wrap my head around what a use-case for |
Beta Was this translation helpful? Give feedback.
-
Both! The WebAssembly namespace is basically a very low level foreign interface with C like levels of abstraction. As far as types go, the most complex thing it knows about are numbers (integers and floating point). To get things like strings out of WebAssembly you treat integers as pointers and copy blocks of memory, it's all very C like. Tools like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to fetch a WebAssembly module from the server with the new
WebAssembly.instantiateStreaming, which works fine for Rust functions with number arguments but returnsundefinedwhen a function with string arguments is called.The Rust code:
It's compiled with
wasm-pack build --target weband then served like this:Then I run the following code client-side with Deno after the server is up and running:
addworks as expected butgreetreturns undefined instead ofHello, World!. I though it might have something to do with usingformat!So I've tried to returnString::from(name)as well with the sameundefinedresult. Is this not a recommended way to compile WebAssembly for Deno or is it perhaps not possible to convert the Rust mutableStringtype to a JavaScript string in this way? If you need more information I'd be happy to provide it.My
deno --version:deno 1.13.0 (release, x86_64-unknown-linux-gnu) <-- Ubuntu WSL 2 v8 9.3.345.11 typescript 4.3.5Beta Was this translation helpful? Give feedback.
All reactions