Louis f88b90f71e
fix(napi-derive): call flush on the BufWriter (#2195)
This is mandated by the Rust doc of the BufWriter. We've also seen bugs where
the data doesn't seem to be flushed properly, and thus the CLI fails to parse
JSONs emitted by napi-derive. This might be it, or not, but flushing shouldn't
hurt.
2024-07-23 21:08:13 +08:00
..
2024-07-16 13:06:00 +08:00

napi-derive

chat

Checkout more examples in examples folder

#[macro_use]
extern crate napi_derive;
use napi::bindgen_prelude::*;

#[napi]
fn fibonacci(n: u32) -> u32 {
  match n {
    1 | 2 => 1,
    _ => fibonacci_native(n - 1) + fibonacci_native(n - 2),
  }
}

#[napi]
fn get_cwd<T: Fn(String) -> Result<()>>(callback: T) {
  callback(env::current_dir().unwrap().to_string_lossy().to_string()).unwrap();
}