Skip to content

Commit c890dc3

Browse files
authored
Document that error types other than JsValue are supported (#3054)
Resolves #1004 #2710 added support for returning `Result<T, impl Into<JsValue>>` rather than just `Result<T, JsValue>`, but the `wasm-bindgen` guide still claims that only the latter is supported. This fixes that, and also fixes a mistake in the table for what forms `Result` can be returned in (it previously claimed that only `Option<Result<...>>` was supported, when in fact only a plain `Result<...>` is supported).
1 parent 5f1b436 commit c890dc3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

guide/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
- [`String`](./reference/types/string.md)
5959
- [Number Slices](./reference/types/number-slices.md)
6060
- [Boxed Number Slices](./reference/types/boxed-number-slices.md)
61-
- [`Result<T, JsValue>`](./reference/types/result.md)
61+
- [`Result<T, E>`](./reference/types/result.md)
6262
- [`#[wasm_bindgen]` Attributes](./reference/attributes/index.md)
6363
- [On JavaScript Imports](./reference/attributes/on-js-imports/index.md)
6464
- [`catch`](./reference/attributes/on-js-imports/catch.md)

guide/src/reference/types/result.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# `Result<T, JsValue>`
1+
# `Result<T, E>`
22

33
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation |
44
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
5-
| No | No | No | No | No | Yes | Same as `T`, or an exception |
5+
| No | No | No | Yes | No | No | Same as `T`, or an exception |
66

77
The `Result` type can be returned from functions exported to JS as well as
8-
closures in Rust. Only `Result<T, JsValue>` is supported where `T` can be
9-
converted to JS. Whenever `Ok(val)` is encountered it's converted to JS and
10-
handed off, and whenever `Err(error)` is encountered an exception is thrown in
11-
JS with `error`.
8+
closures in Rust. The `Ok` type must be able to be converted to JS, and the
9+
`Err` type must implement `Into<JsValue>`. Whenever `Ok(val)` is encountered
10+
it's converted to JS and handed off, and whenever `Err(error)` is encountered
11+
an exception is thrown in JS with `error`.
1212

1313
You can use `Result` to enable handling of JS exceptions with `?` in Rust,
1414
naturally propagating it upwards to the wasm boundary. Furthermore you can also

0 commit comments

Comments
 (0)