pub struct JsFunction(_);

Implementations§

source§

impl JsFunction

See Working with JavaScript Functions.

Example:

use napi::{JsFunction, CallContext, JsNull, Result};

#[js_function(1)]
pub fn call_function(ctx: CallContext) -> Result<JsNull> {
    let js_func = ctx.get::<JsFunction>(0)?;
    let js_string = ctx.env.create_string("hello".as_ref())?.into_unknown()?;
    js_func.call(None, &[js_string])?;
    Ok(ctx.env.get_null()?)
}
source

pub fn call<V>(&self, this: Option<&JsObject>, args: &[V]) -> Result<JsUnknown>where
V: NapiRaw,

source

pub fn call_without_args(&self, this: Option<&JsObject>) -> Result<JsUnknown>

napi_call_function The same with call, but without arguments

source

pub fn new_instance<V>(&self, args: &[V]) -> Result<JsObject>where
V: NapiRaw,

https://nodejs.org/api/n-api.html#n_api_napi_new_instance

This method is used to instantiate a new JavaScript value using a given JsFunction that represents the constructor for the object.

source

pub fn name(&self) -> Result<String>

function name

source

pub fn create_threadsafe_function<T, V, F, ES>(
&self,
max_queue_size: usize,
callback: F
) -> Result<ThreadsafeFunction<T, ES>>where
T: 'static,
V: ToNapiValue,
F: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
ES: T,

source§

impl JsFunction

source

pub fn into_unknown(self) -> JsUnknown

source

pub fn coerce_to_bool(self) -> Result<JsBoolean>

source

pub fn coerce_to_number(self) -> Result<JsNumber>

source

pub fn coerce_to_string(self) -> Result<JsString>

source

pub fn coerce_to_object(self) -> Result<JsObject>

source

pub fn is_date(&self) -> Result<bool>

source

pub fn is_promise(&self) -> Result<bool>

source

pub fn is_error(&self) -> Result<bool>

source

pub fn is_typedarray(&self) -> Result<bool>

source

pub fn is_dataview(&self) -> Result<bool>

source

pub fn is_array(&self) -> Result<bool>

source

pub fn is_buffer(&self) -> Result<bool>

source

pub fn instanceof<Constructor>(&self, constructor: Constructor) -> Result<bool>where
Constructor: NapiRaw,

Trait Implementations§

source§

impl<'env> NapiRaw for &'env JsFunction

source§

unsafe fn raw(&self) -> napi_value

source§

impl NapiRaw for JsFunction

source§

unsafe fn raw(&self) -> napi_value

source§

impl NapiValue for JsFunction

source§

impl TryFrom<JsUnknown> for JsFunction

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: JsUnknown) -> Result<JsFunction>

Performs the conversion.
source§

impl TypeName for JsFunction

source§

impl ValidateNapiValue for JsFunction

source§

unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>

Safety Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> JsValuesTupleIntoVec for Twhere
T: ToNapiValue,

source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.