Struct nj_core::val::JsEnv

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

Implementations§

source§

impl JsEnv

source

pub fn new(env: napi_env) -> Self

source

pub fn inner(&self) -> napi_env

source

pub fn create_string_utf8(&self, r_string: &str) -> Result<napi_value, NjError>

source

pub fn create_string_utf8_from_bytes( &self, r_string: &[u8] ) -> Result<napi_value, NjError>

source

pub fn create_double(&self, value: f64) -> Result<napi_value, NjError>

source

pub fn create_int64(&self, value: i64) -> Result<napi_value, NjError>

source

pub fn create_int32(&self, value: i32) -> Result<napi_value, NjError>

source

pub fn create_uint32(&self, value: u32) -> Result<napi_value, NjError>

source

pub fn create_bigint_uint64(&self, value: u64) -> Result<napi_value, NjError>

source

pub fn create_object(&self) -> Result<napi_value, NjError>

source

pub fn create_boolean(&self, value: bool) -> Result<napi_value, NjError>

source

pub fn create_array_with_len(&self, len: usize) -> Result<napi_value, NjError>

source

pub fn set_element( &self, object: napi_value, element: napi_value, index: usize ) -> Result<(), NjError>

source

pub fn get_element( &self, array: napi_value, index: u32 ) -> Result<napi_value, NjError>

source

pub fn is_array(&self, array: napi_value) -> Result<bool, NjError>

check if napi value is array

source

pub fn is_array_buffer(&self, array: napi_value) -> Result<bool, NjError>

check if napi value is array buffer

source

pub fn is_buffer(&self, n_value: napi_value) -> Result<bool, NjError>

source

pub fn is_date(&self, n_value: napi_value) -> Result<bool, NjError>

source

pub fn is_error(&self, n_value: napi_value) -> Result<bool, NjError>

source

pub fn get_global(&self) -> Result<napi_value, NjError>

source

pub fn call_function( &self, recv: napi_value, func: napi_value, argv: Vec<napi_value> ) -> Result<napi_value, NjError>

source

pub fn get_cb_info( &self, info: napi_callback_info, max_count: usize ) -> Result<JsCallback, NjError>

get callback information

source

pub fn define_class( &self, name: &str, constructor: napi_callback_raw, properties: PropertiesBuilder ) -> Result<napi_value, NjError>

define classes

source

pub fn create_reference( &self, cons: napi_value, count: u32 ) -> Result<napi_ref, NjError>

source

pub fn delete_reference(&self, ref_: napi_ref) -> Result<(), NjError>

source

pub fn get_new_target( &self, info: napi_callback_info ) -> Result<napi_value, NjError>

source

pub fn wrap( &self, js_object: napi_value, rust_obj: *mut u8, finalize: napi_finalize_raw ) -> Result<napi_ref, NjError>

source

pub fn unwrap<T>(&self, js_this: napi_value) -> Result<&'static T, NjError>

source

pub fn unwrap_mut<T>( &self, js_this: napi_value ) -> Result<&'static mut T, NjError>

source

pub fn new_instance( &self, constructor: napi_value, args: Vec<napi_value> ) -> Result<napi_value, NjError>

source

pub fn get_reference_value( &self, obj_ref: napi_ref ) -> Result<napi_value, NjError>

source

pub fn create_promise(&self) -> Result<(napi_value, napi_deferred), NjError>

create promise and deferred

source

pub fn resolve_deferred( &self, deferred: napi_deferred, resolution: napi_value ) -> Result<(), NjError>

source

pub fn reject_deferred( &self, deferred: napi_deferred, rejection: napi_value ) -> Result<(), NjError>

source

pub fn create_thread_safe_function( &self, name: &str, js_func: Option<napi_value>, call_js_cb: napi_threadsafe_function_call_js ) -> Result<ThreadSafeFunction, NjError>

source

pub fn is_exception_pending(&self) -> bool

source

pub fn throw(&self, value: napi_value)

source

pub fn throw_type_error(&self, message: &str)

source

pub fn create_error(&self, message: &str) -> Result<napi_value, NjError>

source

pub fn value_type( &self, napi_value: napi_value ) -> Result<napi_valuetype, NjError>

get value type

source

pub fn value_type_string( &self, napi_value: napi_value ) -> Result<&'static str, NjError>

get string representation of value type

source

pub fn assert_type( &self, napi_value: napi_value, should_be_type: napi_valuetype ) -> Result<(), NjError>

assert that napi value is certain type, otherwise raise exception

source

pub fn convert_to_rust<'a, T>( &'a self, napi_value: napi_value ) -> Result<T, NjError>where T: JSValue<'a>,

convert napi value to rust value

source

pub fn get_undefined(&self) -> Result<napi_value, NjError>

source

pub fn get_null(&self) -> Result<napi_value, NjError>

source

pub fn get_buffer_info(&self, napi_value: napi_value) -> Result<&[u8], NjError>

get buffer info

source

pub fn detach_arraybuffer(&self, napi_value: napi_value) -> Result<(), NjError>

Detach ArrayBuffer

source

pub fn is_detached_arraybuffer( &self, napi_value: napi_value ) -> Result<bool, NjError>

Is this ArrayBuffer Detached?

source

pub unsafe fn add_env_clean_up_hook( &self, init_func: Option<unsafe extern "C" fn(arg: *mut c_void)>, arg: *mut c_void ) -> Result<(), NjError>

Trait Implementations§

source§

impl Clone for JsEnv

source§

fn clone(&self) -> JsEnv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for JsEnv

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ExtractArgFromJs<'_> for JsEnv

source§

fn convert_arg_at(js_cb: &JsCallback, _index: usize) -> Result<Self, NjError>

convert js callback argument at index
source§

fn label() -> &'static str

source§

impl ExtractFromJs<'_> for JsEnv

source§

fn extract(js_cb: &mut JsCallback) -> Result<Self, NjError>

extract from js callback
source§

fn label() -> &'static str

source§

impl From<*mut napi_env__> for JsEnv

source§

fn from(env: napi_env) -> Self

Converts to this type from the input type.
source§

impl Copy for JsEnv

source§

impl Send for JsEnv

source§

impl Sync for JsEnv

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more