JsFunction

Struct JsFunction 

Source
pub struct JsFunction(/* private fields */);
๐Ÿ‘ŽDeprecated since 2.17.0: Please use Function instead

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

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<Unknown<'_>>
where V: NapiRaw,

Source

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

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, NewArgs, Return, ErrorStatus, F, const ES: bool, const Weak: bool, const MaxQueueSize: usize>( &self, callback: F, ) -> Result<ThreadsafeFunction<T, Return, NewArgs, ErrorStatus, ES, Weak, MaxQueueSize>>
where T: 'static, NewArgs: 'static + JsValuesTupleIntoVec, Return: FromNapiValue, F: 'static + Send + FnMut(ThreadsafeCallContext<T>) -> Result<NewArgs>, ErrorStatus: AsRef<str> + From<Status>,

Sourceยง

impl JsFunction

Source

pub fn into_unknown<'env>(self) -> Unknown<'env>

Source

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

Source

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

Source

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

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 is_arraybuffer(&self) -> Result<bool>

Source

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

Trait Implementationsยง

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

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>,

Sourceยง

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.