Skip to content

Commit

Permalink
guide: Add exported rust type examples to reference
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Aug 13, 2018
1 parent f4012de commit 8e19645
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
15 changes: 14 additions & 1 deletion examples/guide-supported-types-examples/exported_types.js
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);
6 changes: 2 additions & 4 deletions examples/guide-supported-types-examples/imported_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
}
16 changes: 15 additions & 1 deletion examples/guide-supported-types-examples/src/exported_types.rs
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!()
}
2 changes: 1 addition & 1 deletion guide/src/reference/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8e19645

Please sign in to comment.