Crates.io | napi-rs-derive |
lib.rs | napi-rs-derive |
version | 0.2.0 |
source | src |
created_at | 2020-04-26 12:22:32.825583 |
updated_at | 2020-05-09 07:40:00.758086 |
description | N-API procedural macros |
homepage | |
repository | https://github.com/Brooooooklyn/napi-rs |
max_upload_size | |
id | 234255 |
size | 5,591 |
#[macro_use]
extern crate napi_rs_derive;
use napi_rs::{Result, Value, CallContext, Number};
use std::convert::TryInto;
#[js_function(1)]
fn fibonacci(ctx: CallContext) -> Result<Value<Number>> {
let n = ctx.get::<Number>(0)?.try_into()?;
ctx.env.create_int64(fibonacci_native(n))
}
#[inline]
fn fibonacci_native(n: i64) -> i64 {
match n {
1 | 2 => 1,
_ => fibonacci_native(n - 1) + fibonacci_native(n - 2)
}
}