Debian Codegraph @

.cargo/vendor/wasm-bindgen/guide/src/introduction.md

raw
1 # Introduction
2
3 This book is about `wasm-bindgen`, a Rust library and CLI tool that facilitate
4 high-level interactions between wasm modules and JavaScript. The `wasm-bindgen`
5 tool and crate are only one part of the [Rust and WebAssembly
6 ecosystem][rustwasm]. If you're not familiar already with `wasm-bindgen` it's
7 recommended to start by reading the [Game of Life tutorial][gol]. If you're
8 curious about `wasm-pack`, you can find that [documentation here][wasm-pack].
9
10 The `wasm-bindgen` tool is sort of half polyfill for features like the
11 [component model proposal][component-model] and half features for empowering high-level
12 interactions between JS and wasm-compiled code (currently mostly from Rust).
13 More specifically this project allows JS/wasm to communicate with strings, JS
14 objects, classes, etc, as opposed to purely integers and floats. Using
15 `wasm-bindgen` for example you can define a JS class in Rust or take a string
16 from JS or return one. The functionality is growing as well!
17
18 Currently this tool is Rust-focused but the underlying foundation is
19 language-independent, and it's hoping that over time as this tool stabilizes
20 that it can be used for languages like C/C++!
21
22 Notable features of this project includes:
23
24 * Importing JS functionality in to Rust such as [DOM manipulation][dom-ex],
25 [console logging][console-log], or [performance monitoring][perf-ex].
26 * Exporting Rust functionality to JS such as classes, functions, etc.
27 * Working with rich types like strings, numbers, classes, closures, and objects
28 rather than simply `u32` and floats.
29 * Automatically generating TypeScript bindings for Rust code being consumed by
30 JS.
31
32 With the addition of [`wasm-pack`][wasm-pack] you can run the gamut from running Rust on
33 the web locally, publishing it as part of a larger application, or even
34 publishing Rust-compiled-to-WebAssembly on NPM!
35
36 [component-model]: https://github.com/WebAssembly/component-model
37 [dom-ex]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/dom
38 [console-log]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/console_log
39 [perf-ex]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/performance
40 [hello-online]: https://webassembly.studio/?f=gzubao6tg3
41 [rustwasm]: https://rustwasm.github.io/
42 [gol]: https://rustwasm.github.io/docs/book/
43 [wasm-pack]: https://rustwasm.github.io/docs/wasm-pack/