Struct v8::Weak

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

An object reference that does not prevent garbage collection for the object, and which allows installing finalization callbacks which will be called after the object has been GC’d.

Note that finalization callbacks are tied to the lifetime of a Weak<T>, and will not be called after the Weak<T> is dropped.

Clone

Since finalization callbacks are specific to a Weak<T> instance, cloning will create a new object reference without a finalizer, as if created by Self::new. You can use Self::clone_with_finalizer to attach a finalization callback to the clone.

Implementations§

Create a weak handle with a finalization callback installed.

There is no guarantee as to when the finalization callback will be invoked. However, unlike the C++ API, this API guarantees that when an isolate is destroyed, any finalizers that haven’t been called yet will be run, unless a Global reference is keeping the object alive. Other than that, there is still no guarantee as to when the finalizers will be called.

The callback does not have access to the inner value, because it has already been collected by the time it runs.

Creates a new empty handle, identical to one for an object that has already been GC’d.

Clones this handle and installs a finalizer callback on the clone, as if by calling Self::with_finalizer.

Note that if this handle is empty (its value has already been GC’d), the finalization callback will never run.

Converts an optional raw pointer created with Weak::into_raw() back to its original Weak.

This method is called with Some, the pointer is invalidated and it cannot be used with this method again. Additionally, it is unsound to call this method with an isolate other than that in which the original Weak was created.

Consume this Weak handle and return the underlying raw pointer, or None if the value has been GC’d.

The return value can be converted back into a Weak by using Weak::from_raw. Note that Weak allocates some memory, and if this method returns Some, the pointer must be converted back into a Weak for it to be freed.

Note that this method might return Some even after the V8 value has been GC’d.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.