File tree Expand file tree Collapse file tree 2 files changed +33
-17
lines changed
examples/guide-supported-types-examples Expand file tree Collapse file tree 2 files changed +33
-17
lines changed Original file line number Diff line number Diff line change 1
1
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
7
10
} from './guide_supported_types_examples' ;
8
11
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 ) ;
11
19
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
Original file line number Diff line number Diff line change 1
1
use wasm_bindgen:: prelude:: * ;
2
2
3
3
#[ wasm_bindgen]
4
- pub struct ExportedRustType {
5
- inner : u32 ,
4
+ pub struct ExportedNamedStruct {
5
+ pub inner : u32 ,
6
6
}
7
7
8
8
#[ wasm_bindgen]
9
- pub fn exported_type_by_value ( x : ExportedRustType ) { }
9
+ pub fn named_struct_by_value ( x : ExportedNamedStruct ) { }
10
10
11
11
#[ wasm_bindgen]
12
- pub fn exported_type_by_shared_ref ( x : & ExportedRustType ) { }
12
+ pub fn named_struct_by_shared_ref ( x : & ExportedNamedStruct ) { }
13
13
14
14
#[ wasm_bindgen]
15
- pub fn exported_type_by_exclusive_ref ( x : & mut ExportedRustType ) { }
15
+ pub fn named_struct_by_exclusive_ref ( x : & mut ExportedNamedStruct ) { }
16
16
17
17
#[ 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)
20
28
}
You can’t perform that action at this time.
0 commit comments