deno_bindgen
deno_bindgen copied to clipboard
Support `Vec<T: Serialize>` return types
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 }
}