Skip to content

wasm_bindgen on async fn doesn't accept same types that it does on regular fn #2541

Open
@RReverser

Description

@RReverser

Describe the Bug

Currently #[wasm_bindgen] on async fn seems to only accept types that are Into<JsValue>, but many wasm-bindgen types are only IntoWasmAbi, making it hard to convert synchronous code into asynchronous.

Steps to Reproduce

Try to compile code like following:

use wasm_bindgen::Clamped;

#[wasm_bindgen]
pub fn foo() -> Clamped<Vec<u8>> {
  Clamped(vec![])
}

#[wasm_bindgen]
pub async fn foo() -> Clamped<Vec<u8>> {
  Clamped(vec![])
}

Expected Behavior

Both functions compile successfully and generate their bindings.

Actual Behavior

Second function fails to compile due to:

   | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ the trait `From<Clamped<Vec<u8>>>` is not implemented for `JsValue`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions