2018-09-20 16:20:42 -07:00
|
|
|
# web-sys: Closures
|
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[View full source code][code] or [view the compiled example online][online]
|
2018-09-20 16:20:42 -07:00
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/closures/
|
2018-09-20 16:20:42 -07:00
|
|
|
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/closures
|
|
|
|
|
|
|
|
One of the features of `#[wasm_bindgen]` is that you can pass closures defined
|
|
|
|
in Rust off to JS. This can be a bit tricky at times, though, so the example
|
|
|
|
here shows how to interact with some standard web APIs with closures.
|
|
|
|
|
|
|
|
## `src/lib.rs`
|
|
|
|
|
|
|
|
```rust
|
|
|
|
{{#include ../../../examples/closures/src/lib.rs}}
|
|
|
|
```
|