forked from rustwasm/wasm-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guide: Add exported rust type examples to reference
- Loading branch information
Showing
4 changed files
with
32 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
console.log("todo") | ||
import { | ||
ExportedRustType, | ||
exported_type_by_value, | ||
exported_type_by_shared_ref, | ||
exported_type_by_exclusive_ref, | ||
return_exported_type, | ||
} from './guide_supported_types_examples'; | ||
|
||
let rustThing = return_exported_type(); | ||
console.log(rustThing instanceof ExportedRustType); // true | ||
|
||
exported_type_by_value(rustThing); | ||
exported_type_by_shared_ref(rustThing); | ||
exported_type_by_exclusive_ref(rustThing); |
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
16 changes: 15 additions & 1 deletion
16
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,6 +1,20 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct RustType { | ||
pub struct ExportedRustType { | ||
inner: u32, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_value(x: ExportedRustType) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_shared_ref(x: &ExportedRustType) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn exported_type_by_exclusive_ref(x: &mut ExportedRustType) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn return_exported_type() -> ExportedRustType { | ||
unimplemented!() | ||
} |
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