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 Vec<T: Serialize> return types #58

Closed
littledivy opened this issue Feb 17, 2022 · 0 comments · Fixed by #136
Closed

Support Vec<T: Serialize> return types #58

littledivy opened this issue Feb 17, 2022 · 0 comments · Fixed by #136
Labels
enhancement New feature or request
Milestone

Comments

@littledivy
Copy link
Member

littledivy commented Feb 17, 2022

Currently, one has to wrap it around another struct and return it. The macro should parse Vec<T> something like this:

use deno_bindgen::deno_bindgen;

#[deno_bindgen]
pub struct UsbDevice {
  // ...
}

#[deno_bindgen(non_blocking)]
pub fn devices() -> Vec<UsbDevice> {
  let ctx = crate::Context::init().unwrap();
  let devices = ctx.devices().unwrap();
  devices
}

Workaround:

#[deno_bindgen]
pub struct Devices {
  devices: Vec<UsbDevice>,
}

#[deno_bindgen(non_blocking)]
pub fn devices() -> Devices {
  let ctx = crate::Context::init().unwrap();
  let devices = ctx.devices().unwrap();
  Devices { devices }
}
@littledivy littledivy added the enhancement New feature or request label Feb 17, 2022
@littledivy littledivy added this to the 0.6.0 milestone Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant