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

Update documentation on extern C async #3250

Closed
matthiasgeihs opened this issue Jan 20, 2023 · 1 comment
Closed

Update documentation on extern C async #3250

matthiasgeihs opened this issue Jan 20, 2023 · 1 comment

Comments

@matthiasgeihs
Copy link

matthiasgeihs commented Jan 20, 2023

Motivation

Was getting some unexpected behavior when working with extern "C" in combination with async.

#[wasm_bindgen]
extern "C" {
    async fn f() -> String;
}

This does not compile.

mismatched types
expected struct `std::string::String`, found struct `wasm_bindgen::JsValue`

Currently it seems like we cannot have return type different than JsValue. (Implementing From<JsValue> doesn't help.) However, there appears to be no information on this in the official documentation.

After some searching, I found some background info on this in the PR implementing the functionality: #2196 (comment). Basically it seems that only return types JsValue is supported.

Proposed Solution

Add relevant information about allowed return types in async extern C to official documentation.

(Might create a PR for this myself if I find time, but wanted to document here now.)

@matthiasgeihs
Copy link
Author

My bad: The documentation actually mentions that the return type must be JsValue or ().

https://rustwasm.github.io/wasm-bindgen/reference/js-promises-and-rust-futures.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant