Struct nodex_api::scope::NapiEscapableHandleScope
source · [−]pub struct NapiEscapableHandleScope(_, _);
Expand description
When nesting scopes, there are cases where a handle from an inner scope needs to live beyond the lifespan of that scope. Node-API supports an ‘escapable scope’ in order to support this case. An escapable scope allows one handle to be ‘promoted’ so that it ‘escapes’ the current scope and the lifespan of the handle changes from the current scope to that of the outer scope.
The methods available to open/close escapable scopes are napi_open_escapable_handle_scope and napi_close_escapable_handle_scope.
The request to promote a handle is made through napi_escape_handle which can only be called once.
Implementations
sourceimpl NapiEscapableHandleScope
impl NapiEscapableHandleScope
pub fn env(&self) -> NapiEnv
pub fn raw(&self) -> napi_escapable_handle_scope
sourcepub fn open(env: NapiEnv) -> NapiResult<NapiEscapableHandleScope>
pub fn open(env: NapiEnv) -> NapiResult<NapiEscapableHandleScope>
This API opens a new scope from which one object can be promoted to the outer scope.
sourcepub fn close(&mut self) -> NapiResult<()>
pub fn close(&mut self) -> NapiResult<()>
This API closes the scope passed in. Scopes must be closed in the reverse order from which they were created. This API can be called even if there is a pending JavaScript exception.
sourcepub fn escape<T: NapiValueT>(&mut self, escapee: T) -> NapiResult<T>
pub fn escape<T: NapiValueT>(&mut self, escapee: T) -> NapiResult<T>
This API promotes the handle to the JavaScript object so that it is valid for the lifetime of the outer scope. It can only be called once per scope. If it is called more than once an error will be returned.
This API can be called even if there is a pending JavaScript exception.
Trait Implementations
sourceimpl Clone for NapiEscapableHandleScope
impl Clone for NapiEscapableHandleScope
sourcefn clone(&self) -> NapiEscapableHandleScope
fn clone(&self) -> NapiEscapableHandleScope
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for NapiEscapableHandleScope
impl Debug for NapiEscapableHandleScope
Auto Trait Implementations
impl RefUnwindSafe for NapiEscapableHandleScope
impl !Send for NapiEscapableHandleScope
impl !Sync for NapiEscapableHandleScope
impl Unpin for NapiEscapableHandleScope
impl UnwindSafe for NapiEscapableHandleScope
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more