Struct napi::JsFunction

source ·
pub struct JsFunction(/* private fields */);

Implementations§

source§

impl JsFunction

source

pub fn apply0<Return: FromNapiValue, Context: ToNapiValue>( &self, this: Context ) -> Result<Return>

source

pub fn call0<Return: FromNapiValue>(&self) -> Result<Return>

source

pub fn call1<Arg1: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1 ) -> Result<Return>

source

pub fn apply1<Arg1: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1 ) -> Result<Return>

source

pub fn call2<Arg1: ToNapiValue, Arg2: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2 ) -> Result<Return>

source

pub fn apply2<Arg1: ToNapiValue, Arg2: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2 ) -> Result<Return>

source

pub fn call3<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3 ) -> Result<Return>

source

pub fn apply3<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3 ) -> Result<Return>

source

pub fn call4<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4 ) -> Result<Return>

source

pub fn apply4<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4 ) -> Result<Return>

source

pub fn call5<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5 ) -> Result<Return>

source

pub fn apply5<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5 ) -> Result<Return>

source

pub fn call6<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6 ) -> Result<Return>

source

pub fn apply6<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6 ) -> Result<Return>

source

pub fn call7<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7 ) -> Result<Return>

source

pub fn apply7<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7 ) -> Result<Return>

source

pub fn call8<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8 ) -> Result<Return>

source

pub fn apply8<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8 ) -> Result<Return>

source

pub fn call9<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Arg9: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8, Arg9: Arg9 ) -> Result<Return>

source

pub fn apply9<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Arg9: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8, Arg9: Arg9 ) -> Result<Return>

source

pub fn call10<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Arg9: ToNapiValue, Arg10: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8, Arg9: Arg9, Arg10: Arg10 ) -> Result<Return>

source

pub fn apply10<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Arg5: ToNapiValue, Arg6: ToNapiValue, Arg7: ToNapiValue, Arg8: ToNapiValue, Arg9: ToNapiValue, Arg10: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, Arg5: Arg5, Arg6: Arg6, Arg7: Arg7, Arg8: Arg8, Arg9: Arg9, Arg10: Arg10 ) -> Result<Return>

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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromNapiValue for T
where T: NapiValue,

source§

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

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 T
where T: ToNapiValue,

source§

impl<T> ToNapiValue for T
where T: NapiRaw,

source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.