-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Question] Convenient way of accessing complex structs from memory in wasm #367
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
Comments
So your struct is still basically The general idea sounds appealing, but I think we need some design work done to hash out all the implementation details. +cc @alexcrichton |
Indeed it'd be great to support this! This is similar in spirit to #111 but perhaps not the exact same. Currently as Rust objects that live in JS are actually just wrappers around an integer pointer. The underlying Rust object, however, is typically It's safe to say, regardless, that this isn't implemented today so you're not missing any features! |
Yes, that's exactly what I had in my mind @fitzgen ! I guess a good starting point would be an enhanced and automatically generated JavaScript class for the structs exported from Rust that accepts a location in memory and wraps access to the struct's fields in a nice way by hiding calls to array views. I am not sure if I can grasp the whole implications of such a feature, but as far as I understand making it read-only would certainly be nice, but also would not change that much? Please correct me if I'am wrong as I have just started with wasm, but as of now you can easily edit the memory of wasm applications directly via JavaScript without caring about the ownership system of Rust (I never tried to do it, though)? So adding a nice wrapper in JS wouldn't change anything here? Nevertheless, having it read-only is of course a better solution @alexcrichton :) |
Ah so the readonly piece is sort of about reentrancy across the language boundary (a fancy way of saying JS calls Rust which calls JS which calls back into Rust). That's a case where you can relatively easily violate Rust's guarantees about In any case though the read-only is mostly just a detail, this'd still need to be fleshed out regardless! |
This is perhaps another candidate for an RFC, once we agree on an RFC process |
I'm gonna close this for now as I think the question was answered, but we can of course file follow-up issues if necessary! |
Hi all,
I am currently learning Rust+WebAssembly and I came across a common problem. When accessing the
memory
of my wasm application from JavaScript I use Uint8Arrays and so on which, works fine most of the time. But this becomes quite complex when I have a struct or even anVec
of structs in my memory. For now, I am extracting the fields of the structs manually by utilizing e.g. Uint8Arrays but I was wondering if there is a more convenient way of doing this? Did I miss something there or is there an easier approach?What I have in my mind is something like an automatically generated JavaScript class based on the struct in Rust that you can pass a pointer to. This class might be just a wrapper around accessing the memory parts directly, but it would be nice to have.
Is there something similar to this already there?
Oh and btw: If this is anyhow helpful for you, I assembled a Docker image with all the tools installed for doing the "game of life" tutorial including the new wasm32-unknown-unknown toolchain. You can find it here https://hub.docker.com/r/jibbow/rust-wasm32-unknown-unknown/
The text was updated successfully, but these errors were encountered: