This is the unpublished documentation of wasm-bindgen, the published documentation is available on the main Rust and WebAssembly documentation site . Features documented here may not be available in released versions of wasm-bindgen.


When attached to a pub struct field this indicates that it's read-only from JavaScript, and a setter will not be generated and exported to JavaScript.

# #![allow(unused_variables)]
#fn main() {
pub fn make_foo() -> Foo {
    Foo {
        first: 10,
        second: 20,

pub struct Foo {
    pub first: u32,

    pub second: u32,

Here the first field will be both readable and writable from JS, but the second field will be a readonly field in JS where the setter isn't implemented and attempting to set it will throw an exception.

import { make_foo } from "./my_module";

const foo = make_foo();

// Can both get and set `first`.
foo.first = 99;

// Can only get `second`.