guide: Add exported rust type examples to reference

This commit is contained in:
Nick Fitzgerald 2018-08-13 16:03:02 -07:00
parent f4012defac
commit 8e19645006
4 changed files with 32 additions and 7 deletions

View File

@ -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);

View File

@ -10,8 +10,7 @@ imported_type_by_value(new SomeJsType());
imported_type_by_shared_ref(new SomeJsType()); imported_type_by_shared_ref(new SomeJsType());
let x = return_imported_type(); let x = return_imported_type();
console.log(x instanceof SomeJsType); console.log(x instanceof SomeJsType); // true
// true
take_option_imported_type(null); take_option_imported_type(null);
take_option_imported_type(undefined); take_option_imported_type(undefined);
@ -21,6 +20,5 @@ let y = return_option_imported_type();
if (y == null) { if (y == null) {
// ... // ...
} else { } else {
console.log(y instanceof SomeJsType); console.log(y instanceof SomeJsType); // true
// true
} }

View File

@ -1,6 +1,20 @@
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
pub struct RustType { pub struct ExportedRustType {
inner: u32, 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!()
}

View File

@ -26,7 +26,7 @@ JavaScript.
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation | | `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 ### Example Rust Usage