Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document support for Option<RustStruct> #2821

Merged

Conversation

Globidev
Copy link
Contributor

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.
The relevant page on the official website even appear to explicitly say that it is not supported:
image

I then found out about PR #1275 which seems to implement both OptionIntoWasmAbi and OptionFromWasmAbi for any #[wasm_bindgen] annotated rust struct. If I'm understanding everything correctly, then those two columns should be switched to Yes.

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.

Comment on lines -16 to +20
named_struct_by_value(namedStruct);
named_struct_by_shared_ref(namedStruct);
named_struct_by_exclusive_ref(namedStruct);
named_struct_by_value(namedStruct);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I switched the by_value call at the end because calling it actually invalidates the underlying pointer (since it's supposed to be moved on the rust side), meaning calling named_struct_by_shared_ref or named_struct_by_exclusive_ref afterwards would produce an error

@alexcrichton alexcrichton merged commit a608959 into rustwasm:main Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants