Debian Codegraph @

.cargo/vendor/wasm-bindgen/guide/src/examples/import-js.md

raw
1 # Importing non-browser JS
2
3 [View full source code][code] or [view the compiled example online][online]
4
5 [online]: https://rustwasm.github.io/wasm-bindgen/exbuild/import_js/
6 [code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/import_js
7
8 The `#[wasm_bindgen]` attribute can be used on `extern "C" { .. }` blocks to import
9 functionality from JS. This is how the `js-sys` and the `web-sys` crates are
10 built, but you can also use it in your own crate!
11
12 For example if you're working with this JS file:
13
14 ```js
15 // defined-in-js.js
16 {{#include ../../../examples/import_js/crate/defined-in-js.js}}
17 ```
18
19 you can use it in Rust with:
20
21 ```rust
22 {{#include ../../../examples/import_js/crate/src/lib.rs}}
23 ```
24
25 You can also [explore the full list of ways to configure imports][attr]
26
27 [attr]: ../reference/attributes/on-js-imports/index.html