Document support for Option<RustStruct> #2821
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on a project of my own I intuitively attempted to return an
Option<MyRustType>
from a#[wasm_bindgen]
annotated function and it worked as expected.I later realized that support for that is not currently documented in the docs.
![image](https://user-images.githubusercontent.com/2079561/155880300-662bc0bb-0f6b-4f52-9729-cbac15a207db.png)
The relevant page on the official website even appear to explicitly say that it is not supported:
I then found out about PR #1275 which seems to implement both
OptionIntoWasmAbi
andOptionFromWasmAbi
for any#[wasm_bindgen]
annotated rust struct. If I'm understanding everything correctly, then those two columns should be switched toYes
.This PR adjusts the markdown to reflect the support for
Option<RustStruct>
in both parameter and return type position while also adding some use cases in the relevant rust and javascript examples.