Struct neon::handle::Root

source ·
pub struct Root<T> { /* private fields */ }
Expand description

A thread-safe handle that holds a reference to a JavaScript object and prevents it from being garbage collected.

A Root<T> may be sent across threads, but the referenced object may only be accessed on the JavaScript thread that created it.

Implementations§

Create a reference to a JavaScript object. The object will not be garbage collected until the Root is dropped. A Root<T> may only be dropped on the JavaScript thread that created it.

The caller should ensure Root::into_inner or Root::drop is called to properly dispose of the Root<T>. If the value is dropped without calling one of these methods:

  • N-API < 6, Neon will panic to notify of the leak
  • N-API >= 6, Neon will drop from a global queue at a runtime cost

Clone a reference to the contained JavaScript object. This method can be considered identical to the following:

let inner = root.into_inner(&mut cx);
let cloned = inner.root(&mut cx);
let root = inner.root(&mut cx);

Safely drop a Root<T> without returning the referenced JavaScript object.

Return the referenced JavaScript object and allow it to be garbage collected.

Panics

This method panics if it is called from a different JavaScript thread than the one in which the handle was created.

Access the inner JavaScript object without consuming the Root This method aliases the reference without changing the reference count. It can be used in place of a clone immediately followed by a call to into_inner.

Panics

This method panics if it is called from a different JavaScript thread than the one in which the handle was created.

Trait Implementations§

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.