Struct napi::bindgen_prelude::JsFunction
source · [−]pub struct JsFunction(_);
Implementations
sourceimpl 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,
sourceimpl 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
sourceimpl NapiRaw for JsFunction
impl NapiRaw for JsFunction
unsafe fn raw(&self) -> napi_value
sourceimpl<'env> NapiRaw for &'env JsFunction
impl<'env> NapiRaw for &'env JsFunction
unsafe fn raw(&self) -> napi_value
sourceimpl 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
sourceimpl TryFrom<JsUnknown> for JsFunction
impl TryFrom<JsUnknown> for JsFunction
sourceimpl TypeName for JsFunction
impl TypeName for JsFunction
sourceimpl ValidateNapiValue for JsFunction
impl ValidateNapiValue for JsFunction
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more