mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
guide: Add exported rust type examples to reference
This commit is contained in:
parent
f4012defac
commit
8e19645006
@ -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);
|
||||
|
@ -10,8 +10,7 @@ imported_type_by_value(new SomeJsType());
|
||||
imported_type_by_shared_ref(new SomeJsType());
|
||||
|
||||
let x = return_imported_type();
|
||||
console.log(x instanceof SomeJsType);
|
||||
// true
|
||||
console.log(x instanceof SomeJsType); // true
|
||||
|
||||
take_option_imported_type(null);
|
||||
take_option_imported_type(undefined);
|
||||
@ -21,6 +20,5 @@ let y = return_option_imported_type();
|
||||
if (y == null) {
|
||||
// ...
|
||||
} else {
|
||||
console.log(y instanceof SomeJsType);
|
||||
// true
|
||||
console.log(y instanceof SomeJsType); // true
|
||||
}
|
||||
|
@ -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!()
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ JavaScript.
|
||||
|
||||
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation |
|
||||
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||
| Yes | Yes | Yes | Yes | Yes | Yes | Instances of a `wasm-bindgen`-generated JavaScript `class Whatever { ... }` |
|
||||
| Yes | Yes | Yes | Yes | No | No | Instances of a `wasm-bindgen`-generated JavaScript `class Whatever { ... }` |
|
||||
|
||||
### Example Rust Usage
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user