Skip to content

Commit a0a3a14

Browse files
committed
Include props usage in exported_types example
1 parent 3a7d384 commit a0a3a14

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import {
2-
ExportedRustType,
3-
exported_type_by_value,
4-
exported_type_by_shared_ref,
5-
exported_type_by_exclusive_ref,
6-
return_exported_type,
2+
ExportedNamedStruct,
3+
named_struct_by_value,
4+
named_struct_by_shared_ref,
5+
named_struct_by_exclusive_ref,
6+
return_named_struct,
7+
8+
ExportedTupleStruct,
9+
return_tuple_struct
710
} from './guide_supported_types_examples';
811

9-
let rustThing = return_exported_type();
10-
console.log(rustThing instanceof ExportedRustType); // true
12+
let namedStruct = return_named_struct(42);
13+
console.log(namedStruct instanceof ExportedNamedStruct); // true
14+
console.log(namedStruct.inner); // 42
15+
16+
named_struct_by_value(namedStruct);
17+
named_struct_by_shared_ref(namedStruct);
18+
named_struct_by_exclusive_ref(namedStruct);
1119

12-
exported_type_by_value(rustThing);
13-
exported_type_by_shared_ref(rustThing);
14-
exported_type_by_exclusive_ref(rustThing);
20+
let tupleStruct = return_tuple_struct(10, 20);
21+
console.log(tupleStruct instanceof ExportedTupleStruct); // true
22+
console.log(tupleStruct[0], tupleStruct[1]); // 10, 20
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
use wasm_bindgen::prelude::*;
22

33
#[wasm_bindgen]
4-
pub struct ExportedRustType {
5-
inner: u32,
4+
pub struct ExportedNamedStruct {
5+
pub inner: u32,
66
}
77

88
#[wasm_bindgen]
9-
pub fn exported_type_by_value(x: ExportedRustType) {}
9+
pub fn named_struct_by_value(x: ExportedNamedStruct) {}
1010

1111
#[wasm_bindgen]
12-
pub fn exported_type_by_shared_ref(x: &ExportedRustType) {}
12+
pub fn named_struct_by_shared_ref(x: &ExportedNamedStruct) {}
1313

1414
#[wasm_bindgen]
15-
pub fn exported_type_by_exclusive_ref(x: &mut ExportedRustType) {}
15+
pub fn named_struct_by_exclusive_ref(x: &mut ExportedNamedStruct) {}
1616

1717
#[wasm_bindgen]
18-
pub fn return_exported_type() -> ExportedRustType {
19-
unimplemented!()
18+
pub fn return_named_struct(inner: u32) -> ExportedNamedStruct {
19+
ExportedNamedStruct { inner }
20+
}
21+
22+
#[wasm_bindgen]
23+
pub struct ExportedTupleStruct(pub u32, pub u32);
24+
25+
#[wasm_bindgen]
26+
pub fn return_tuple_struct(x: u32, y: u32) -> ExportedTupleStruct {
27+
ExportedTupleStruct(x, y)
2028
}

0 commit comments

Comments
 (0)