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

Cannot return Tsify types from async methods with wasm-bindgen-futures #53

Open
hoxxep opened this issue May 13, 2024 · 4 comments
Open

Comments

@hoxxep
Copy link

hoxxep commented May 13, 2024

The crate tests are failing as per below in many cases on the js feature which means we cannot return rust types in methods and have them automatically cast to JS objects.

-        impl From<JsType> for JsValue {
-            #[inline]
-            fn from(obj: JsType) -> JsValue {
-                obj.obj.into()
-            }
-        }
-        impl JsCast for JsType {
-        ...
-        }

This is broken on both the tests on master (as per ./test.sh) and per the deployed crate.

Let me know if you're aware of a quick fix, or can point me to a likely culprit? Thanks!

@hoxxep
Copy link
Author

hoxxep commented May 13, 2024

The tests are failing for me locally, but I've noticed my actual issue in production occurs only when trying to return Tsify types under wasm_bindgen on async methods.

For example, using features = ["js"]:

use serde::{Deserialize, Serialize};
use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;

#[derive(Tsify, Serialize, Deserialize)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Example {
    a: i32,
}

/// Compiles successfully
#[wasm_bindgen]
pub fn example_sync() -> Example {
    Example { a: 42 }
}

/// Error, fails to compile
#[wasm_bindgen]
pub async fn example_async() -> Example {
    Example { a: 42 }
}

The sync method compiles successfully, but the async method fails to compile with the error:

error[E0277]: the trait bound `JsValue: From<Example>` is not satisfied
  --> src/lib.rs:12:33
   |
12 | pub async fn example(a: i32) -> Example {
   |                                 ^^^^^^^ the trait `From<Example>` is not implemented for `JsValue`, which is required by `Example: IntoJsResult`
...
   = note: required for `Example` to implement `Into<JsValue>`
   = note: required for `Example` to implement `IntoJsResult`

@hoxxep hoxxep changed the title js feature not implementing JsCast, JsType etc Cannot return Tsify types from async methods with wasm-bindgen-futures May 13, 2024
@hoxxep
Copy link
Author

hoxxep commented May 13, 2024

This now appears to be a duplicate of issue #24.

@Pantamis
Copy link

Pantamis commented Aug 8, 2024

I implemented it in tsify-next fork: siefkenj#22

Should do the job let me know !

@sucaba
Copy link

sucaba commented Aug 13, 2024

I implemented it in tsify-next fork: siefkenj#22

Should do the job let me know !

Thanks, man! You saved my release day

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