Struct FinalizationRegistry

#[repr(transparent)]
pub struct FinalizationRegistry { /* private fields */ }

The FinalizationRegistry object lets you request a callback when an object is garbage-collected.

FinalizationRegistry provides a way to request that a cleanup callback get called at some point when an object registered with the registry has been reclaimed (garbage-collected). Cleanup callbacks are sometimes called finalizers.

Avoid where possible: cleanup callbacks should not be relied upon for anything essential. They are best used to reduce memory usage over the course of a program for objects that benefit from cleanup. Whether, when, and in what order callbacks fire is implementation-defined.

MDN documentation

Implementations

impl FinalizationRegistry

fn register(&self, target: &JsValue, held_value: &JsValue)

Registers target with this FinalizationRegistry. When target is reclaimed by the garbage collector the cleanup callback may be called with held_value.

target must be an object (or a non-registered symbol).

MDN documentation

impl FinalizationRegistry

fn register_with_token(&self, target: &JsValue, held_value: &JsValue, unregister_token: &JsValue)

Registers target with this FinalizationRegistry, with an unregister_token that can later be passed to FinalizationRegistry::unregister to remove the registration.

target and unregister_token must be objects (or non-registered symbols), and the same value may be passed for both.

MDN documentation

impl FinalizationRegistry

fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry

Creates a new FinalizationRegistry with the given cleanup callback.

The cleanup callback is invoked, at some point after a registered target is garbage-collected, with the held_value that was passed to FinalizationRegistry::register. Because callbacks may be deferred or skipped entirely, the callback should normally outlive the FinalizationRegistry (for example by being created via Function::from_closure).

MDN documentation

impl FinalizationRegistry

fn unregister(&self, unregister_token: &JsValue) -> bool

Unregisters all entries registered with this FinalizationRegistry using unregister_token. Returns true if any cells were removed.

MDN documentation

Trait Implementations

impl AsRef<FinalizationRegistry> for FinalizationRegistry

fn as_ref(&self) -> &FinalizationRegistry

impl AsRef<JsValue> for FinalizationRegistry

fn as_ref(&self) -> &JsValue

impl AsRef<Object> for FinalizationRegistry

fn as_ref(&self) -> &Object

impl Clone for FinalizationRegistry

fn clone(&self) -> Self

impl Debug for FinalizationRegistry

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

impl Deref for FinalizationRegistry

type Target = Object;
fn deref(&self) -> &Object

impl Eq for FinalizationRegistry

impl ErasableGeneric for FinalizationRegistry

type Repr = JsValue;

impl From<JsValue> for FinalizationRegistry

fn from(obj: JsValue) -> Self

impl FromWasmAbi for FinalizationRegistry

type Abi = <JsValue as FromWasmAbi>::Abi;
unsafe fn from_abi(js: Self::Abi) -> Self

impl IntoJsGeneric for FinalizationRegistry where FinalizationRegistry: JsGeneric,

type JsCanon = FinalizationRegistry;
fn to_js(self) -> FinalizationRegistry

impl IntoWasmAbi for FinalizationRegistry

type Abi = <JsValue as IntoWasmAbi>::Abi;
fn into_abi(self) -> Self::Abi

impl JsCast for FinalizationRegistry

fn instanceof(val: &JsValue) -> bool
fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self

impl LongRefFromWasmAbi for FinalizationRegistry

type Abi = <JsValue as LongRefFromWasmAbi>::Abi;
type Anchor = FinalizationRegistry;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

impl OptionFromWasmAbi for FinalizationRegistry

fn is_none(abi: &Self::Abi) -> bool

impl OptionIntoWasmAbi for FinalizationRegistry

fn none() -> Self::Abi

impl PartialEq for FinalizationRegistry

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

impl Promising for FinalizationRegistry

type Resolution = FinalizationRegistry;

impl RefFromWasmAbi for FinalizationRegistry

type Abi = <JsValue as RefFromWasmAbi>::Abi;
type Anchor = ManuallyDrop<FinalizationRegistry>;
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

impl StructuralPartialEq for FinalizationRegistry

impl UpcastFrom<FinalizationRegistry> for FinalizationRegistry

impl WasmDescribe for FinalizationRegistry

fn describe()

Auto Trait Implementations

impl Freeze for FinalizationRegistry

impl RefUnwindSafe for FinalizationRegistry

impl Send for FinalizationRegistry

impl Sync for FinalizationRegistry

impl Unpin for FinalizationRegistry

impl UnsafeUnpin for FinalizationRegistry

impl UnwindSafe for FinalizationRegistry

Blanket Implementations

impl<P, T> Receiver for FinalizationRegistry where P: Deref<Target = T> + ?Sized, T: ?Sized,

impl<S, T> Upcast<T> for FinalizationRegistry where T: UpcastFrom<S> + ?Sized, S: ?Sized,

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

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

impl<T> BorrowMut<T> for FinalizationRegistry where T: ?Sized,

impl<T> CloneToUninit for FinalizationRegistry where T: Clone,

impl<T> From<T> for FinalizationRegistry

impl<T> JsGeneric for FinalizationRegistry where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,

impl<T> ReturnWasmAbi for FinalizationRegistry where T: IntoWasmAbi,

impl<T> ToOwned for FinalizationRegistry where T: Clone,

impl<T> TryFromJsValue for FinalizationRegistry where T: JsCast,

impl<T> VectorFromWasmAbi for FinalizationRegistry where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorIntoWasmAbi for FinalizationRegistry where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorRefIntoWasmAbi for FinalizationRegistry where &'a T: for<'a> Into<JsValue>,

impl<T, U> Into<U> for FinalizationRegistry where U: From<T>,

impl<T, U> TryFrom<U> for FinalizationRegistry where U: Into<T>,

impl<T, U> TryInto<U> for FinalizationRegistry where U: TryFrom<T>,