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

Support for Tuples and Tuple Struct #1372

Open
CMCDragonkai opened this issue Nov 22, 2022 · 3 comments
Open

Support for Tuples and Tuple Struct #1372

CMCDragonkai opened this issue Nov 22, 2022 · 3 comments
Labels

Comments

@CMCDragonkai
Copy link

Is there a reason why we cannot export a tuple struct or tuple to the JS side?

#[napi]
pub fn plus_100(input: u32) -> (u32, u32) {
  (input, input)
}

#[napi]
pub struct X(u32, u32);

#[napi]
pub fn plus_200(input: u32) -> X {
  X(input, input)
}

In the first case, the macro complains:

the trait bound `(u32, u32): NapiRaw` is not satisfied
required because of the requirements on the impl of `napi::bindgen_prelude::ToNapiValue` for `(u32, u32)`

In the second case, the macros don't complain, but on the JS side, I get a X object with no properties...

On the JS side I would be expecting a heterogeneous array of some sort.

@CMCDragonkai CMCDragonkai changed the title Support for Tuple Struct Support for Tuples and Tuple Struct Nov 22, 2022
@Brooooooklyn
Copy link
Sponsor Member

@CMCDragonkai I think it was because there is no Tuple in JavaScript

@CMCDragonkai
Copy link
Author

But there are arrays in JS, it'd be nice if rust tuples just auto converted to JS arrays.

@CMCDragonkai
Copy link
Author

Plus typescript tuples are just fixed size arrays.

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

No branches or pull requests

2 participants