-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
255 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
async fn main() {} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-async.rs:7:4 | ||
| | ||
7 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::fmt; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() -> Result<(), Test> { | ||
unimplemented!() | ||
} | ||
|
||
struct Test; | ||
|
||
impl fmt::Debug for Test { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-debug.rs:18:4 | ||
| | ||
18 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::convert::Infallible; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() -> Infallible { | ||
unimplemented!() | ||
} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-infallible.rs:10:4 | ||
| | ||
10 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() -> Result<(), JsValue> { | ||
unimplemented!() | ||
} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-jsvalue.rs:9:4 | ||
| | ||
9 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::process; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() -> Test { | ||
unimplemented!() | ||
} | ||
|
||
struct Test; | ||
|
||
impl process::Termination for Test { | ||
fn report(self) -> process::ExitCode { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-termination.rs:18:4 | ||
| | ||
18 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() -> () {} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main-unit.rs:7:4 | ||
| | ||
7 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(main)] | ||
fn main() {} | ||
|
||
#[wasm_bindgen(main)] | ||
fn fail() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: the main function has to be called main | ||
--> ui-tests/main.rs:7:4 | ||
| | ||
7 | fn fail() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# `main` | ||
|
||
When attached to the `fn main()` function this attribute will adjust it to | ||
properly throw errors if they can be. This is only intended to be used for | ||
binaries. | ||
|
||
```rust | ||
#[wasm_bindgen(main)] | ||
fn main() -> Result<(), JsValue> { | ||
Err(JsValue::from("this error message will be thrown")) | ||
} | ||
``` | ||
|
||
The attribute also allows using `async fn main()` in Cargo binaries. | ||
|
||
```rust | ||
#[wasm_bindgen(main)] | ||
async fn main() { | ||
// ... | ||
future.await; | ||
} | ||
``` | ||
|
||
Unlike `#[wasm_bindgen(start)]` this will not export a function to be executed | ||
on startup, it should only be used in Cargo binaries or examples for the `main` | ||
function. `#[wasm_bindgen(start)]` will prevent the `main` function to start and | ||
should not be used in conjunction. | ||
|
||
Any return value that is supported by Rust is supported here, see | ||
[`Termination`]. In order, wasm-bindgen will first detect a | ||
`Result<(), impl Into<JsValue>>` and will throw proper `JsValue`s, | ||
`Result<(), impl Debug>` will convert an error to a string and throw that. | ||
Lastly anything implementing [`Termination`] will throw it's reported | ||
[`ExitCode`](https://doc.rust-lang.org/std/process/struct.ExitCode.html) by | ||
using it's `Debug` representation. | ||
|
||
[`termination`]: https://doc.rust-lang.org/std/process/trait.Termination.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters