chore: remove lifetime param in example

This commit is contained in:
LongYinan 2020-05-02 00:21:38 +08:00
parent 0a388056ad
commit f751ea3b2a
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
3 changed files with 4 additions and 4 deletions

View file

@ -29,7 +29,7 @@ One nice feature is that this crate allows you to build add-ons purely with the
## Taste ## Taste
```rust ```rust
#[js_function(1)] // ------> arguments length, omit for zero #[js_function(1)] // ------> arguments length, omit for zero
fn fibonacci<'env>(ctx: CallContext<'env>) -> Result<Value<'env, Number>> { fn fibonacci(ctx: CallContext) -> Result<Value<Number>> {
let n = ctx.get::<Number>(0)?.try_into()?; let n = ctx.get::<Number>(0)?.try_into()?;
ctx.env.create_int64(fibonacci_native(n)) ctx.env.create_int64(fibonacci_native(n))
} }

View file

@ -19,12 +19,12 @@ fn init<'env>(
} }
#[js_function] #[js_function]
fn test_throw<'a>(_ctx: CallContext) -> Result<Value<'a, Any>> { fn test_throw(_ctx: CallContext) -> Result<Value<Any>> {
Err(Error::new(Status::GenericFailure)) Err(Error::new(Status::GenericFailure))
} }
#[js_function(1)] #[js_function(1)]
fn fibonacci<'env>(ctx: CallContext<'env>) -> Result<Value<'env, Number>> { fn fibonacci(ctx: CallContext) -> Result<Value<Number>> {
let n = ctx.get::<Number>(0)?.try_into()?; let n = ctx.get::<Number>(0)?.try_into()?;
ctx.env.create_int64(fibonacci_native(n)) ctx.env.create_int64(fibonacci_native(n))
} }

View file

@ -10,7 +10,7 @@ use napi_rs::{Result, Value, CallContext, Number};
use std::convert::TryInto; use std::convert::TryInto;
#[js_function(1)] #[js_function(1)]
fn fibonacci<'env>(ctx: CallContext<'env>) -> Result<Value<'env, Number>> { fn fibonacci(ctx: CallContext) -> Result<Value<Number>> {
let n = ctx.get::<Number>(0)?.try_into()?; let n = ctx.get::<Number>(0)?.try_into()?;
ctx.env.create_int64(fibonacci_native(n)) ctx.env.create_int64(fibonacci_native(n))
} }