Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

What's the idiomatic way to return a Vec<T> where T is tsify(into_wasm_abi)? #3692

Closed
hillin opened this issue Nov 8, 2023 · 0 comments
Closed
Labels

Comments

@hillin
Copy link

hillin commented Nov 8, 2023

With #111 we can now return a Vec<T> if T is #[wasm_bindgen]:

#[wasm_bindgen]
struct Thing(u32);

#[wasm_bindgen]
pub fn get_numbers() -> Vec<Thing> {
    vec![Thing(1), Thing(2), Thing(3)]
}

But it does not work if T is tsified:

#[derive(serde::Serialize, serde::Deserialize, tsify::Tsify)]
#[tsify(into_wasm_abi)]
struct Thing(u32);

  #[wasm_bindgen]
/*^^^^^^^^^^^^^^^ the trait `JsObject` is not implemented for `Thing`
    = help: the following other types implement trait `JsObject`:
              js_sys::Array
              js_sys::ArrayBuffer
              web_sys::features::gen_AudioBuffer::AudioBuffer
              js_sys::SharedArrayBuffer
              web_sys::features::gen_AudioBufferSourceNode::AudioBufferSourceNode
              js_sys::BigInt
              web_sys::features::gen_AudioContext::AudioContext
              web_sys::features::gen_AudioDestinationNode::AudioDestinationNode
            and 164 others
    = note: required for `Thing` to implement `WasmDescribeVector`
    = note: required for `Box<[Thing]>` to implement `WasmDescribe`
    = note: 1 redundant requirement hidden
    = note: required for `Vec<Thing>` to implement `WasmDescribe`
note: required by a bound in `ReturnWasmAbi`
   --> wasm-bindgen-0.2.88\src\convert\traits.rs:176:26
    |
176 | pub trait ReturnWasmAbi: WasmDescribe {
    |                          ^^^^^^^^^^^^ required by this bound in `ReturnWasmAbi`
    = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
*/
pub fn get_numbers() -> Vec<Thing> {
    vec![Thing(1), Thing(2), Thing(3)]
}
@hillin hillin added the question label Nov 8, 2023
@rustwasm rustwasm locked and limited conversation to collaborators Nov 9, 2023
@daxpedda daxpedda converted this issue into discussion #3697 Nov 9, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

1 participant