From fedd1a544014bc1babb4a8801eafa2f07b19d7f9 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 13 Aug 2018 16:55:05 -0700 Subject: [PATCH] guide: Add `bool` example to supported types section --- examples/guide-supported-types-examples/bool.js | 9 +++++++++ examples/guide-supported-types-examples/src/bool.rs | 9 +++++++++ examples/guide-supported-types-examples/src/lib.rs | 1 + guide/src/reference/types.md | 12 ++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 examples/guide-supported-types-examples/bool.js create mode 100644 examples/guide-supported-types-examples/src/bool.rs diff --git a/examples/guide-supported-types-examples/bool.js b/examples/guide-supported-types-examples/bool.js new file mode 100644 index 00000000..3276d1a7 --- /dev/null +++ b/examples/guide-supported-types-examples/bool.js @@ -0,0 +1,9 @@ +import { + take_char_by_value, + return_char, +} from './guide_supported_types_examples'; + +take_bool_by_value(true); + +let b = return_bool(); +console.log(typeof b); // "boolean" diff --git a/examples/guide-supported-types-examples/src/bool.rs b/examples/guide-supported-types-examples/src/bool.rs new file mode 100644 index 00000000..43edb430 --- /dev/null +++ b/examples/guide-supported-types-examples/src/bool.rs @@ -0,0 +1,9 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn take_bool_by_value(x: bool) {} + +#[wasm_bindgen] +pub fn return_bool() -> bool { + true +} diff --git a/examples/guide-supported-types-examples/src/lib.rs b/examples/guide-supported-types-examples/src/lib.rs index 6265796c..0ed9d397 100755 --- a/examples/guide-supported-types-examples/src/lib.rs +++ b/examples/guide-supported-types-examples/src/lib.rs @@ -8,3 +8,4 @@ pub mod exported_types; pub mod str; pub mod string; pub mod char; +pub mod bool; diff --git a/guide/src/reference/types.md b/guide/src/reference/types.md index edd15a03..f15ae3be 100644 --- a/guide/src/reference/types.md +++ b/guide/src/reference/types.md @@ -109,6 +109,18 @@ garbage-collected heap and the Wasm linear memory with `TextDecoder` and |:---:|:---:|:---:|:---:|:---:|:---:|:---:| | Yes | No | No | Yes | No | No | A JavaScript boolean value | +### Example Rust Usage + +```rust +{{#include ../../../examples/guide-supported-types-examples/src/bool.rs}} +``` + +### Example JavaScript Usage + +```js +{{#include ../../../examples/guide-supported-types-examples/bool.js}} +``` + ## `wasm_bindgen::JsValue` | `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option` parameter | `Option` return value | JavaScript representation |