Sha256: 93f94a1b670322d0dc21b46d749909c414f9f254e2dd97afd8afe8cb0e5ab908

Contents?: true

Size: 1.08 KB

Versions: 30

Compression:

Stored size: 1.08 KB

Contents

# Working with the `char` type

[View full source code][code] or [view the compiled example online][online]

[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/char/
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/char

The `#[wasm_bindgen]` macro will convert the rust `char` type to a single
code-point js `string`, and this example shows how to work with this.

Opening this example should display a single counter with a random character
for it's `key` and 0 for its `count`. You can click the `+` button to increase a
counter's count. By clicking on the "add counter" button you should see a new
counter added to the list with a different random character for it's `key`.

Under the hood javascript is choosing a random character from an Array of
characters and passing that to the rust Counter struct's constructor so the
character you are seeing on the page has made the full round trip from js to
rust and back to js.

## `src/lib.rs`

```rust
{{#include ../../../examples/char/src/lib.rs}}
```

## `index.js`

```js
{{#include ../../../examples/char/index.js}}
```

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-22.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-21.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-20.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-20.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-18.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-17.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-17.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-16.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-15.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-15.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/char.md
wasmtime-14.0.4 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-14.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-14.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-14.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-13.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-12.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-12.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-11.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md
wasmtime-10.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/char.md