deno_bindgen icon indicating copy to clipboard operation
deno_bindgen copied to clipboard

Support `Vec<T: Serialize>` return types

Open littledivy opened this issue 3 years ago • 0 comments
trafficstars

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 avatar Feb 17 '22 10:02 littledivy