-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to expose a function to Javascript that takes a Uint32Array and returns a Uint32Array? #2402
Comments
Hmm, okay so I think what I might need to do is have the function take a https://rustwasm.github.io/wasm-bindgen/reference/types/boxed-number-slices.html And one of the code snippets gives me the same error:
Also results in me getting the same runtime error. Is it possible this used to be allowed but is now different and the docs haven't been updated? Or maybe I'm doing something else wrong? |
Ah, it appears that was an unrelated bug (from here: rustwasm/wasm-pack#886 (comment)) and it has now compiled. Nice, progress! |
You should be able to return |
I am a newbie too and I encountered this problem, I wrote a dummy function to test but it did not work:
In the frontend the rust module is loaded like this:
The strange thing is after compiling the rust-wasm pack, the
|
That's happening because you're importing the wrong file: you should be importing
|
Actually, when using the ".js" file I was not even able to get the result from the I am actually not sure how much of the problem angular-related, also if there is another way to make the import using js that would fix the problem I would appreciate to know how :-) |
The repo you linked instantiates the Wasm module by itself calling Unfortunately I know nothing about Angular, but it would certainly help to see the code again you changed to get to where you are now. |
Hello, sorry for the noob question but I am extremely new to WASM and this is the final step I need to get my code working, and I can't quite figure it out.
For my website I am looking to offload a very intensive computation to WASM, and I thought Rust would be a good fit for this. Basically, I would like to send a matrix from Javascript to my WASM library and have it process it and then return a new matrix.
I have already written all the Rust code that computes the matrix (in Rust I am using a Vec) and I have verified that it works. The only thing I need to do now is somehow figure out how to get Javascript to be able to send a Uint32Array to this function and then have it send back a Uint32Array back to Javascript.
Unfortunately, I am getting some errors. First I tried doing this:
But that was giving me this compiler error:
I thought maybe it was because it was only supported for
u32
and notusize
and that it's not allowed to be a mutable reference, so I had my function take aVec<u32>
instead and just clone the vec in the function back to usize, and that kind of worked, except now I'm getting a runtime error.When I run
wasm-pack build
I get around 1000 pages of compiled WASM text output, and I have figured out that it is due to me trying to return aVec<u32
from the function. If I remove the return value then it compiles successfully. For some reason it is not letting me return aVec<u32>
, but I'm not sure why. I thought that it would allow this but Javascript would just interpret it as aUint32Array
.I was looking through the runtime compile logs and found these snippets:
The text was updated successfully, but these errors were encountered: