-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1467 from RReverser/tuple-structs
Generate bindings for indexed struct properties
- Loading branch information
Showing
7 changed files
with
78 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 18 additions & 10 deletions
28
examples/guide-supported-types-examples/exported_types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { | ||
ExportedRustType, | ||
exported_type_by_value, | ||
exported_type_by_shared_ref, | ||
exported_type_by_exclusive_ref, | ||
return_exported_type, | ||
ExportedNamedStruct, | ||
named_struct_by_value, | ||
named_struct_by_shared_ref, | ||
named_struct_by_exclusive_ref, | ||
return_named_struct, | ||
|
||
ExportedTupleStruct, | ||
return_tuple_struct | ||
} from './guide_supported_types_examples'; | ||
|
||
let rustThing = return_exported_type(); | ||
console.log(rustThing instanceof ExportedRustType); // true | ||
let namedStruct = return_named_struct(42); | ||
console.log(namedStruct instanceof ExportedNamedStruct); // true | ||
console.log(namedStruct.inner); // 42 | ||
|
||
named_struct_by_value(namedStruct); | ||
named_struct_by_shared_ref(namedStruct); | ||
named_struct_by_exclusive_ref(namedStruct); | ||
|
||
exported_type_by_value(rustThing); | ||
exported_type_by_shared_ref(rustThing); | ||
exported_type_by_exclusive_ref(rustThing); | ||
let tupleStruct = return_tuple_struct(10, 20); | ||
console.log(tupleStruct instanceof ExportedTupleStruct); // true | ||
console.log(tupleStruct[0], tupleStruct[1]); // 10, 20 |
22 changes: 15 additions & 7 deletions
22
examples/guide-supported-types-examples/src/exported_types.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct ExportedRustType { | ||
inner: u32, | ||
pub struct ExportedNamedStruct { | ||
pub inner: u32, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_value(x: ExportedRustType) {} | ||
pub fn named_struct_by_value(x: ExportedNamedStruct) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_shared_ref(x: &ExportedRustType) {} | ||
pub fn named_struct_by_shared_ref(x: &ExportedNamedStruct) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_exclusive_ref(x: &mut ExportedRustType) {} | ||
pub fn named_struct_by_exclusive_ref(x: &mut ExportedNamedStruct) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn return_exported_type() -> ExportedRustType { | ||
unimplemented!() | ||
pub fn return_named_struct(inner: u32) -> ExportedNamedStruct { | ||
ExportedNamedStruct { inner } | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct ExportedTupleStruct(pub u32, pub u32); | ||
|
||
#[wasm_bindgen] | ||
pub fn return_tuple_struct(x: u32, y: u32) -> ExportedTupleStruct { | ||
ExportedTupleStruct(x, y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters