Struct napi::JsFunction
source · pub struct JsFunction(/* private fields */);
Implementations§
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
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()?)
}
sourcepub fn call<V>(&self, this: Option<&JsObject>, args: &[V]) -> Result<JsUnknown>where
V: NapiRaw,
pub fn call<V>(&self, this: Option<&JsObject>, args: &[V]) -> Result<JsUnknown>where V: NapiRaw,
sourcepub fn call_without_args(&self, this: Option<&JsObject>) -> Result<JsUnknown>
pub fn call_without_args(&self, this: Option<&JsObject>) -> Result<JsUnknown>
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, 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
impl JsFunction
pub fn into_unknown(self) -> JsUnknown
pub fn coerce_to_bool(self) -> Result<JsBoolean>
pub fn coerce_to_number(self) -> Result<JsNumber>
pub fn coerce_to_string(self) -> Result<JsString>
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 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<JsUnknown> for JsFunction
impl TryFrom<JsUnknown> 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 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
source§impl<T> FromNapiValue for Twhere
T: NapiValue,
impl<T> FromNapiValue for Twhere T: NapiValue,
source§unsafe fn from_napi_value(
env: *mut napi_env__,
napi_val: *mut napi_value__
) -> Result<T, Error>
unsafe fn from_napi_value( env: *mut napi_env__, napi_val: *mut napi_value__ ) -> Result<T, Error>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self>
source§impl<T> JsValuesTupleIntoVec for Twhere
T: ToNapiValue,
impl<T> JsValuesTupleIntoVec for Twhere T: ToNapiValue,
fn into_vec(self, env: *mut napi_env__) -> Result<Vec<*mut napi_value__>, Error>
source§impl<T> ToNapiValue for Twhere
T: NapiRaw,
impl<T> ToNapiValue for Twhere T: NapiRaw,
source§unsafe fn to_napi_value(
_env: *mut napi_env__,
val: T
) -> Result<*mut napi_value__, Error>
unsafe fn to_napi_value( _env: *mut napi_env__, val: T ) -> Result<*mut napi_value__, Error>
Safety Read more