mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-15 09:40:52 +00:00
guide: also allow Option<bool>
This commit is contained in:
parent
9c9e53485a
commit
fea41b4a87
@ -1,9 +1,22 @@
|
||||
import {
|
||||
take_char_by_value,
|
||||
return_char,
|
||||
take_option_bool,
|
||||
return_option_bool,
|
||||
} from './guide_supported_types_examples';
|
||||
|
||||
take_bool_by_value(true);
|
||||
|
||||
let b = return_bool();
|
||||
console.log(typeof b); // "boolean"
|
||||
|
||||
take_option_bool(null);
|
||||
take_option_bool(undefined);
|
||||
take_option_bool(true);
|
||||
|
||||
let c = return_option_bool();
|
||||
if (c == null) {
|
||||
// ...
|
||||
} else {
|
||||
console.log(typeof c); // "boolean"
|
||||
}
|
||||
|
@ -7,3 +7,11 @@ pub fn take_bool_by_value(x: bool) {}
|
||||
pub fn return_bool() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn take_option_bool(x: Option<bool>) {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_option_bool() -> Option<bool> {
|
||||
Some(false)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ garbage-collected heap and the Wasm linear memory with `TextDecoder` and
|
||||
|
||||
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation |
|
||||
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||
| Yes | No | No | Yes | No | No | A JavaScript boolean value |
|
||||
| Yes | No | No | Yes | Yes | Yes | A JavaScript boolean value |
|
||||
|
||||
### Example Rust Usage
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user