v8

Struct 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>

Source§

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>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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.