| 1 |
# `start` |
| 2 |
|
| 3 |
When attached to a function this attribute will configure the `start` |
| 4 |
section of the wasm executable to be emitted, executing the tagged function as |
| 5 |
soon as the wasm module is instantiated. |
| 6 |
|
| 7 |
```rust |
| 8 |
#[wasm_bindgen(start)] |
| 9 |
fn start() { |
| 10 |
// executed automatically ... |
| 11 |
} |
| 12 |
``` |
| 13 |
|
| 14 |
The `start` section of the wasm executable will be configured to execute the |
| 15 |
`start` function here as soon as it can. Note that due to various practical |
| 16 |
limitations today the start section of the executable may not literally point to |
| 17 |
`start`, but the `start` function here should be started up automatically when the |
| 18 |
wasm module is loaded. |
| 19 |
|
| 20 |
There's a few caveats to be aware of when using the `start` attribute: |
| 21 |
|
| 22 |
* The `start` function must take no arguments and must either return `()` or |
| 23 |
`Result<(), JsValue>` |
| 24 |
* Only one `start` function can be placed into a module, including its |
| 25 |
dependencies. If more than one is specified then `wasm-bindgen` will fail when |
| 26 |
the CLI is run. It's recommended that only applications use this attribute. |
| 27 |
* The `start` function will not be executed when testing. |
| 28 |
* Note that the `start` function is relatively new, so if you find any bugs with |
| 29 |
it, please feel free to report an issue! |