mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
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.
napi-derive
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();
}