Skip to content

Commit ebe99fe

Browse files
authored
#2775: Updated doc - Exported Rust types (#2857)
1 parent 65105ff commit ebe99fe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

examples/guide-supported-types-examples/src/exported_types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ use wasm_bindgen::prelude::*;
22

33
#[wasm_bindgen]
44
pub struct ExportedNamedStruct {
5+
// pub value: String, // This won't work. See working example below.
56
pub inner: u32,
67
}
78

9+
#[wasm_bindgen(getter_with_clone)]
10+
pub struct ExportedNamedStructNonCopy {
11+
pub non_copy_value: String,
12+
pub copy_value: u32,
13+
}
14+
815
#[wasm_bindgen]
916
pub fn named_struct_by_value(x: ExportedNamedStruct) {}
1017

guide/src/reference/types/exported-rust-types.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
55
| Yes | Yes | Yes | Yes | Yes | Yes | Instances of a `wasm-bindgen`-generated JavaScript `class Whatever { ... }` |
66

7+
> **Note**: Public fields implementing Copy have automatically generated getters/setters.
8+
> To generate getters/setters for non-Copy public fields, use #[wasm_bindgen(getter_with_clone)] for the struct
9+
> or [implement getters/setters manually](https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-rust-exports/getter-and-setter.html).
710
## Example Rust Usage
811

912
```rust

0 commit comments

Comments
 (0)