Skip to content

[Question] Convenient way of accessing complex structs from memory in wasm #367

Closed
@andizimmerer

Description

@andizimmerer

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 an Vec 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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions