#[repr(C)]pub struct NapiEnv(_);
Implementations
This API returns the global object.
get node version the returned buffer is statically allocated and does not need to be freed.
get napi version
Return null object
Return undefined object
This API is used to convert from the C int32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
This API is used to convert from the C uint32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
This API is used to convert from the C int64_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification. Note the complete range of int64_t cannot be represented with full precision in JavaScript. Integer values outside the range of Number.MIN_SAFE_INTEGER -(253 - 1) - Number.MAX_SAFE_INTEGER (253 - 1) will lose precision.
This API is used to convert from the C double type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
This API creates a JavaScript string value from a UTF8-encoded C string. The native string is copied. The JavaScript string type is described in Section 6.1.4 of the ECMAScript Language Specification.
Create an empty js array.
Create a boolean.
Create a Buffer
Create a Buffer
Create an ArrayBuffer
This API creates a JavaScript symbol value from a UTF8-encoded C string. The JavaScript symbol type is described in Section 19.4 of the ECMAScript Language Specification.
Symbol with description.
This API allocates a default JavaScript Object. It is the equivalent of doing new Object() in JavaScript. The JavaScript Object type is described in Section 6.1.7 of the ECMAScript Language Specification.
The async context
pub fn external<T>(
&self,
value: T,
finalizer: impl FnOnce(NapiEnv, T) -> NapiResult<()> + 'static
) -> NapiResult<JsExternal<T>>
pub fn external<T>(
&self,
value: T,
finalizer: impl FnOnce(NapiEnv, T) -> NapiResult<()> + 'static
) -> NapiResult<JsExternal<T>>
Create an external data.
pub fn func<T, R, const N: usize>(
&self,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>
) -> NapiResult<Function<R>> where
T: NapiValueT,
R: NapiValueT,
pub fn func<T, R, const N: usize>(
&self,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>
) -> NapiResult<Function<R>> where
T: NapiValueT,
R: NapiValueT,
Create a js function with a rust closure.
pub fn func_named<T, R, const N: usize>(
&self,
name: impl AsRef<str>,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>
) -> NapiResult<Function<R>> where
T: NapiValueT,
R: NapiValueT,
pub fn func_named<T, R, const N: usize>(
&self,
name: impl AsRef<str>,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>
) -> NapiResult<Function<R>> where
T: NapiValueT,
R: NapiValueT,
Create a named js function with a rust closure.
pub fn function_named(
&self,
name: impl AsRef<str>,
func: extern "C" fn(env: NapiEnv, info: napi_callback_info) -> napi_value
) -> NapiResult<Function<JsValue>>
pub fn function_named(
&self,
name: impl AsRef<str>,
func: extern "C" fn(env: NapiEnv, info: napi_callback_info) -> napi_value
) -> NapiResult<Function<JsValue>>
Create a named js function with a rust function
pub fn function(
&self,
func: extern "C" fn(env: NapiEnv, info: napi_callback_info) -> napi_value
) -> NapiResult<Function<JsValue>>
pub fn function(
&self,
func: extern "C" fn(env: NapiEnv, info: napi_callback_info) -> napi_value
) -> NapiResult<Function<JsValue>>
Create a js function with a rust function
pub fn class<T, R, const N: usize>(
&self,
name: impl AsRef<str>,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>,
properties: impl AsRef<[NapiPropertyDescriptor]>
) -> NapiResult<JsClass> where
T: NapiValueT,
R: NapiValueT,
pub fn class<T, R, const N: usize>(
&self,
name: impl AsRef<str>,
func: impl FnMut(JsObject, [T; N]) -> NapiResult<R>,
properties: impl AsRef<[NapiPropertyDescriptor]>
) -> NapiResult<JsClass> where
T: NapiValueT,
R: NapiValueT,
Create a js class with a rust closure
pub fn async_work<T>(
&self,
name: impl AsRef<str>,
state: T,
execute: impl FnMut(&mut T),
complete: impl FnMut(NapiEnv, NapiStatus, T) -> NapiResult<()>
) -> NapiResult<NapiAsyncWork<T>>
pub fn async_work<T>(
&self,
name: impl AsRef<str>,
state: T,
execute: impl FnMut(&mut T),
complete: impl FnMut(NapiEnv, NapiStatus, T) -> NapiResult<()>
) -> NapiResult<NapiAsyncWork<T>>
Create an async work with shared state
pub fn promise<T, L: NapiValueT + Copy + Clone, R: NapiValueT + Copy + Clone>(
&self,
work: impl FnMut(&mut T),
complete: impl FnMut(JsPromise<L, R>, NapiStatus, T) -> NapiResult<()>
) -> NapiResult<JsPromise<L, R>> where
T: Default,
pub fn promise<T, L: NapiValueT + Copy + Clone, R: NapiValueT + Copy + Clone>(
&self,
work: impl FnMut(&mut T),
complete: impl FnMut(JsPromise<L, R>, NapiStatus, T) -> NapiResult<()>
) -> NapiResult<JsPromise<L, R>> where
T: Default,
Create a promise with a work & complete closure.
pub fn define_properties(
&self,
object: impl NapiValueT,
properties: impl AsRef<[NapiPropertyDescriptor]>
) -> NapiResult<()>
pub fn define_properties(
&self,
object: impl NapiValueT,
properties: impl AsRef<[NapiPropertyDescriptor]>
) -> NapiResult<()>
This method allows the efficient definition of multiple properties on a given object. The properties are defined using property descriptors (see napi_property_descriptor). Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by DefineOwnProperty() (described in Section 9.1.6 of the ECMA-262 specification).
This API throws a JavaScript Error with the text provided.
pub fn throw_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
pub fn throw_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
This API throws a JavaScript Error with the text provided.
This API throws a JavaScript TypeError with the text provided.
pub fn throw_type_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
pub fn throw_type_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
This API throws a JavaScript TypeError with the text provided.
pub fn throw_range_error(
&self,
msg: impl AsRef<str>,
code: Option<impl AsRef<str>>
) -> NapiResult<()>
pub fn throw_range_error(
&self,
msg: impl AsRef<str>,
code: Option<impl AsRef<str>>
) -> NapiResult<()>
This API throws a JavaScript TypeError with the text provided.
pub fn throw_range_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
pub fn throw_range_error_code(
&self,
msg: impl AsRef<str>,
code: impl AsRef<str>
) -> NapiResult<()>
This API throws a JavaScript TypeError with the text provided.
Get and clear last exception This API can be called even if there is a pending JavaScript exception.
This API retrieves a napi_extended_error_info structure with information about the last error that occurred.
The content of the napi_extended_error_info returned is only valid up until a Node-API function is called on the same env. This includes a call to napi_is_exception_pending so it may often be necessary to make a copy of the information so that it can be used later. The pointer returned in error_message points to a statically-defined string so it is safe to use that pointer if you have copied it out of the error_message field (which will be overwritten) before another Node-API function was called.
Do not rely on the content or format of any of the extended information as it is not subject to SemVer and may change at any time. It is intended only for logging purposes.
This API can be called even if there is a pending JavaScript exception.
Return true if an exception is pending. This API can be called even if there is a pending JavaScript exception.
Create a handle scope
Create a escapable handle scope
This function gives V8 an indication of the amount of externally allocated memory that is kept alive by JavaScript objects (i.e. a JavaScript object that points to its own memory allocated by a native module). Registering externally allocated memory will trigger global garbage collections more often than it would otherwise.
This function executes a string of JavaScript code and returns its result with the following caveats:
- Unlike eval, this function does not allow the script to access the current lexical scope, and therefore also does not allow to access the module scope, meaning that pseudo-globals such as require will not be available.
- The script can access the global scope. Function and var declarations in the script will be added to the global object. Variable declarations made using let and const will be visible globally, but will not be added to the global object.
- The value of this is global within the script.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NapiEnv
impl UnwindSafe for NapiEnv
Blanket Implementations
Mutably borrows from an owned value. Read more