mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-13 15:46:07 +00:00
guide: Add a char
example to the supported types section
This commit is contained in:
parent
74dc8874e1
commit
975a122d6d
9
examples/guide-supported-types-examples/char.js
Normal file
9
examples/guide-supported-types-examples/char.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import {
|
||||||
|
take_char_by_value,
|
||||||
|
return_char,
|
||||||
|
} from './guide_supported_types_examples';
|
||||||
|
|
||||||
|
take_char_by_value('a');
|
||||||
|
|
||||||
|
let c = return_char();
|
||||||
|
console.log(typeof c); // "string"
|
9
examples/guide-supported-types-examples/src/char.rs
Normal file
9
examples/guide-supported-types-examples/src/char.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn take_char_by_value(x: char) {}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn return_char() -> char {
|
||||||
|
'🚀'
|
||||||
|
}
|
@ -7,3 +7,4 @@ pub mod imported_types;
|
|||||||
pub mod exported_types;
|
pub mod exported_types;
|
||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod string;
|
pub mod string;
|
||||||
|
pub mod char;
|
||||||
|
@ -91,6 +91,18 @@ garbage-collected heap and the Wasm linear memory with `TextDecoder` and
|
|||||||
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||||
| Yes | No | No | Yes | No | No | A JavaScript string value |
|
| Yes | No | No | Yes | No | No | A JavaScript string value |
|
||||||
|
|
||||||
|
### Example Rust Usage
|
||||||
|
|
||||||
|
```rust
|
||||||
|
{{#include ../../../examples/guide-supported-types-examples/src/char.rs}}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example JavaScript Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
{{#include ../../../examples/guide-supported-types-examples/char.js}}
|
||||||
|
```
|
||||||
|
|
||||||
## `bool`
|
## `bool`
|
||||||
|
|
||||||
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation |
|
| `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