Struct v8::Global

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

An object reference that is independent of any handle scope. Where a Local handle only lives as long as the HandleScope in which it was allocated, a global handle remains valid until it is dropped.

A global handle contains a reference to a storage cell within the V8 engine which holds an object value and which is updated by the garbage collector whenever the object is moved.

You can create a v8::Local out of v8::Global using v8::Local::new(scope, global_handle).

Implementations§

source§

impl<T> Global<T>

source

pub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self

Construct a new Global from an existing Handle.

source

pub fn into_raw(self) -> NonNull<T>

Consume this Global and return the underlying raw pointer.

The returned raw pointer must be converted back into a Global by using Global::from_raw, otherwise the V8 value referenced by this global handle will be pinned on the V8 heap permanently and never get garbage collected.

source

pub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self

Converts a raw pointer created with Global::into_raw() back to its original Global.

source

pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T

Trait Implementations§

source§

impl<T> Borrow<T> for Global<T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> Clone for Global<T>

source§

fn clone(&self) -> Self

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<T: Debug> Debug for Global<T>

source§

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

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

impl<T> Drop for Global<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T> Handle for &'a Global<T>

§

type Data = T

source§

fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data

Returns a reference to the V8 heap object that this handle represents. The handle does not get cloned, nor is it converted to a Local handle. Read more
source§

unsafe fn get_unchecked(&self) -> &Self::Data

Reads the inner value contained in this handle, without verifying that the this handle is hosted by the currently active Isolate. Read more
source§

impl<T> Handle for Global<T>

§

type Data = T

source§

fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data

Returns a reference to the V8 heap object that this handle represents. The handle does not get cloned, nor is it converted to a Local handle. Read more
source§

unsafe fn get_unchecked(&self) -> &Self::Data

Reads the inner value contained in this handle, without verifying that the this handle is hosted by the currently active Isolate. Read more
source§

impl<T: Hash> Hash for Global<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, Rhs: Handle> PartialEq<Rhs> for Global<T>
where T: PartialEq<Rhs::Data>,

source§

fn eq(&self, other: &Rhs) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Eq for Global<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> Freeze for Global<T>

§

impl<T> !RefUnwindSafe for Global<T>

§

impl<T> !Send for Global<T>

§

impl<T> !Sync for Global<T>

§

impl<T> Unpin for Global<T>

§

impl<T> !UnwindSafe for Global<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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 T
where 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 T
where 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 T
where 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.