mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-30 16:12:16 +00:00
guide: Add bool
example to supported types section
This commit is contained in:
parent
975a122d6d
commit
fedd1a5440
9
examples/guide-supported-types-examples/bool.js
Normal file
9
examples/guide-supported-types-examples/bool.js
Normal file
@ -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"
|
9
examples/guide-supported-types-examples/src/bool.rs
Normal file
9
examples/guide-supported-types-examples/src/bool.rs
Normal file
@ -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
|
||||
}
|
@ -8,3 +8,4 @@ pub mod exported_types;
|
||||
pub mod str;
|
||||
pub mod string;
|
||||
pub mod char;
|
||||
pub mod bool;
|
||||
|
@ -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<T>` parameter | `Option<T>` return value | JavaScript representation |
|
||||
|
Loading…
x
Reference in New Issue
Block a user