fwd/vendor/wasm-bindgen/guide/src/examples/import-js.md
John Doty 9c435dc440 Vendor dependencies
Let's see how I like this workflow.
2022-12-19 08:38:22 -08:00

843 B

Importing non-browser JS

View full source code or view the compiled example online

The #[wasm_bindgen] attribute can be used on extern "C" { .. } blocks to import functionality from JS. This is how the js-sys and the web-sys crates are built, but you can also use it in your own crate!

For example if you're working with this JS file:

// defined-in-js.js
{{#include ../../../examples/import_js/crate/defined-in-js.js}}

you can use it in Rust with:

{{#include ../../../examples/import_js/crate/src/lib.rs}}

You can also explore the full list of ways to configure imports