Skip to content

Documentation: The "Supported types: number slices" page is confusing #1659

Open
@mstange

Description

@mstange

The documentation about passing number slices between JS and rust is a bit confusing to me, because it doesn't make clear whether there are any copies happening when passing such data, and if they happen, when.

The "Javascript Representation" column currently says:

A JavaScript TypedArray view of the Wasm memory for the boxed slice of the appropriate type (Int32Array, Uint8Array, etc)

First, there is no boxed slice here, this page is about slice references. Second, "view of the Wasm memory" makes it sound like JavaScript has direct access to the wasm module's memory buffer, which is also not the case. Everything is copied.

I recommend changing the "JavaScript Representation" column to just the following:

A JavaScript TypedArray of the appropriate type (Int32Array, Uint8Array, etc)

And then adding the following note about copies underneath:

The contents of the JavaScript TypedArray get copied into wasm memory when the function is called. For arrays which are passed to a &mut T parameter, there is an additional copy: The modified values are copied back out into the JavaScript TypedArray at the end of the function call, so that any mutations are reflected on the JS side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsIssues related to documentationhelp wantedWe could use some help fixing this issue!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions