diff --git a/examples/guide-supported-types-examples/exported_types.js b/examples/guide-supported-types-examples/exported_types.js index 97dd4313..7c60aea8 100644 --- a/examples/guide-supported-types-examples/exported_types.js +++ b/examples/guide-supported-types-examples/exported_types.js @@ -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); diff --git a/examples/guide-supported-types-examples/imported_types.js b/examples/guide-supported-types-examples/imported_types.js index 41d1c682..b3473f79 100644 --- a/examples/guide-supported-types-examples/imported_types.js +++ b/examples/guide-supported-types-examples/imported_types.js @@ -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 } diff --git a/examples/guide-supported-types-examples/src/exported_types.rs b/examples/guide-supported-types-examples/src/exported_types.rs index 018374cb..963cb520 100644 --- a/examples/guide-supported-types-examples/src/exported_types.rs +++ b/examples/guide-supported-types-examples/src/exported_types.rs @@ -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!() +} diff --git a/guide/src/reference/types.md b/guide/src/reference/types.md index a29d61fd..9bcf37b2 100644 --- a/guide/src/reference/types.md +++ b/guide/src/reference/types.md @@ -26,7 +26,7 @@ JavaScript. | `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option` parameter | `Option` 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