pub struct JsFunction(/* private fields */);
๐Deprecated since 2.17.0: Please use
Function
insteadImplementationsยง
Sourceยงimpl JsFunction
impl JsFunction
pub fn apply0<Return: FromNapiValue, Context: ToNapiValue>( &self, this: Context, ) -> Result<Return>
pub fn call0<Return: FromNapiValue>(&self) -> Result<Return>
pub fn call1<Arg1: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, ) -> Result<Return>
pub fn apply1<Arg1: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, ) -> Result<Return>
pub fn call2<Arg1: ToNapiValue, Arg2: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, ) -> Result<Return>
pub fn apply2<Arg1: ToNapiValue, Arg2: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, ) -> Result<Return>
pub fn call3<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, ) -> Result<Return>
pub fn apply3<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Context: ToNapiValue, Return: FromNapiValue>( &self, this: Context, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, ) -> Result<Return>
pub fn call4<Arg1: ToNapiValue, Arg2: ToNapiValue, Arg3: ToNapiValue, Arg4: ToNapiValue, Return: FromNapiValue>( &self, Arg1: Arg1, Arg2: Arg2, Arg3: Arg3, Arg4: Arg4, ) -> Result<Return>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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()?)
}
Sourcepub fn call<V>(
&self,
this: Option<&JsObject>,
args: &[V],
) -> Result<Unknown<'_>>where
V: NapiRaw,
pub fn call<V>(
&self,
this: Option<&JsObject>,
args: &[V],
) -> Result<Unknown<'_>>where
V: NapiRaw,
Sourcepub fn call_without_args(&self, this: Option<&JsObject>) -> Result<Unknown<'_>>
pub fn call_without_args(&self, this: Option<&JsObject>) -> Result<Unknown<'_>>
napi_call_function
The same with call
, but without arguments
Sourcepub fn new_instance<V>(&self, args: &[V]) -> Result<JsObject>where
V: NapiRaw,
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.
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
impl JsFunction
pub fn into_unknown<'env>(self) -> Unknown<'env>
pub fn coerce_to_bool(self) -> Result<JsBoolean>
pub fn coerce_to_number<'env>(self) -> Result<JsNumber<'env>>
pub fn coerce_to_string<'env>(self) -> Result<JsString<'env>>
pub fn coerce_to_object(self) -> Result<JsObject>
pub fn is_date(&self) -> Result<bool>
pub fn is_promise(&self) -> Result<bool>
pub fn is_error(&self) -> Result<bool>
pub fn is_typedarray(&self) -> Result<bool>
pub fn is_dataview(&self) -> Result<bool>
pub fn is_array(&self) -> Result<bool>
pub fn is_buffer(&self) -> Result<bool>
pub fn is_arraybuffer(&self) -> Result<bool>
pub fn instanceof<Constructor>(&self, constructor: Constructor) -> Result<bool>where
Constructor: NapiRaw,
Trait Implementationsยง
Sourceยงimpl<'env> NapiRaw for &'env JsFunction
impl<'env> NapiRaw for &'env JsFunction
unsafe fn raw(&self) -> napi_value
Sourceยงimpl NapiRaw for JsFunction
impl NapiRaw for JsFunction
unsafe fn raw(&self) -> napi_value
Sourceยงimpl NapiValue for JsFunction
impl NapiValue for JsFunction
unsafe fn from_raw(env: napi_env, value: napi_value) -> Result<JsFunction>
unsafe fn from_raw_unchecked(env: napi_env, value: napi_value) -> JsFunction
Sourceยงimpl TryFrom<Unknown<'_>> for JsFunction
impl TryFrom<Unknown<'_>> for JsFunction
Sourceยงimpl TypeName for JsFunction
impl TypeName for JsFunction
Sourceยงimpl ValidateNapiValue for JsFunction
impl ValidateNapiValue for JsFunction
Sourceยงunsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Auto Trait Implementationsยง
impl Freeze for JsFunction
impl RefUnwindSafe for JsFunction
impl !Send for JsFunction
impl !Sync for JsFunction
impl Unpin for JsFunction
impl UnwindSafe for JsFunction
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more