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

Nullable return types #1252

Closed
dbrgn opened this issue Feb 14, 2019 · 4 comments
Closed

Nullable return types #1252

dbrgn opened this issue Feb 14, 2019 · 4 comments

Comments

@dbrgn
Copy link
Contributor

dbrgn commented Feb 14, 2019

This example builds:

#[wasm_bindgen]
pub struct Hello {
    pub a: u32,
}

#[wasm_bindgen]
pub fn say_hello() -> Hello {
    Hello { a: 42 }
}

But when changin the return type of say_hello to an Option, it fails:

#[wasm_bindgen]
pub struct Hello {
    pub a: u32,
}

#[wasm_bindgen]
pub fn say_hello() -> Option<Hello> {
    Some(Hello { a: 42 })
}

Error:

  error[E0277]: the trait bound `Hello: wasm_bindgen::convert::traits::OptionIntoWasmAbi` is not satisfied
    --> examples/hello_world/src/lib.rs:18:1
     |
  18 | #[wasm_bindgen]
     | ^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::traits::OptionIntoWasmAbi` is not implemented for `Hello`
     |
     = note: required because of the requirements on the impl of `wasm_bindgen::convert::traits::IntoWasmAbi` for `std::option::Option<Hello>`

  error: aborting due to previous error

Is this not supported? I would have expected Hello | null as return type.

@dbrgn dbrgn changed the title Handling Option<T> where T uses #[wasm_bindgen] Nullable return types Feb 14, 2019
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Feb 19, 2019
Add all the necessary support in a few locations and we should be good
to go!

Closes rustwasm#1252
@dbrgn
Copy link
Contributor Author

dbrgn commented Mar 4, 2019

@alexcrichton any chance of a new release soon?

@remram44
Copy link

remram44 commented Mar 4, 2019

+1. I've been using the Git repo as dependency (using [patch]), but I also have to install the cli from Git, which is awkward (especially for CI).

@alexcrichton
Copy link
Contributor

Sure thing!

@dbrgn
Copy link
Contributor Author

dbrgn commented Mar 4, 2019

Thanks! ❤️

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

No branches or pull requests

3 participants