pub struct JsExternal<T>(/* private fields */);
Implementations§
Source§impl<T> JsExternal<T>
impl<T> JsExternal<T>
Sourcepub fn new(
env: NapiEnv,
value: T,
finalizer: impl FnOnce(NapiEnv, T) -> NapiResult<()> + 'static,
) -> NapiResult<JsExternal<T>>
pub fn new( env: NapiEnv, value: T, finalizer: impl FnOnce(NapiEnv, T) -> NapiResult<()> + 'static, ) -> NapiResult<JsExternal<T>>
This API allocates a JavaScript value with external data attached to it. This is used to pass external data through JavaScript code, so it can be retrieved later by native code using napi_get_value_external.
Sourcepub fn get(&self) -> NapiResult<&mut T>
pub fn get(&self) -> NapiResult<&mut T>
Access the underlaying data.
Sourcepub fn arraybuffer<'a>(
env: NapiEnv,
value: impl AsRef<[T]>,
) -> NapiResult<JsExternal<&'a [T]>>
pub fn arraybuffer<'a>( env: NapiEnv, value: impl AsRef<[T]>, ) -> NapiResult<JsExternal<&'a [T]>>
This API returns a Node-API value corresponding to a JavaScript ArrayBuffer. The underlying byte buffer of the ArrayBuffer is externally allocated and managed. The caller must ensure that the byte buffer remains valid until the finalize callback is called. The API adds a napi_finalize callback which will be called when the JavaScript object just created is ready for garbage collection. It is similar to napi_wrap() except that:
- the native data cannot be retrieved later using napi_unwrap(),
- nor can it be removed later using napi_remove_wrap(), and
- the object created by the API can be used with napi_wrap(). JavaScript ArrayBuffers are described in Section 24.1 of the ECMAScript Language Specification.
Sourcepub fn buffer<'a>(
env: NapiEnv,
value: impl AsRef<[T]>,
) -> NapiResult<JsExternal<&'a [T]>>
pub fn buffer<'a>( env: NapiEnv, value: impl AsRef<[T]>, ) -> NapiResult<JsExternal<&'a [T]>>
This API allocates a node::Buffer object and initializes it with data backed by the passed in buffer. While this is still a fully-supported data structure, in most cases using a TypedArray will suffice. The API adds a napi_finalize callback which will be called when the JavaScript object just created is ready for garbage collection. It is similar to napi_wrap() except that:
- the native data cannot be retrieved later using napi_unwrap(),
- nor can it be removed later using napi_remove_wrap(), and
- the object created by the API can be used with napi_wrap(). For Node.js >=4 Buffers are Uint8Arrays.
Trait Implementations§
Source§impl<T: Clone> Clone for JsExternal<T>
impl<T: Clone> Clone for JsExternal<T>
Source§fn clone(&self) -> JsExternal<T>
fn clone(&self) -> JsExternal<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more