neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
8k stars 283 forks source link

Convenience types for common globals #958

Open dherman opened 1 year ago

dherman commented 1 year ago

It would be nice to have convenience types for common globals like console, process, and JSON. We could imagine it might look something like:

struct Console<'a> { /* ... */ }

impl<'a> Console<'a> {
    pub fn log<'cx, C: Context<'cx>, A: Arguments>(cx: &mut C, args: A) -> NeonResult<()> { todo!() }
}

let console: Console = cx.console()?;
let hello = cx.string("Hello, World!");

console.log(&mut cx, (hello,));