pub trait Finalize: Sized {
// Provided method
fn finalize<'a, C: Context<'a>>(self, _: &mut C) { ... }
}
Expand description
A trait for finalizing values owned by the main JavaScript thread.
Finalize::finalize
is executed on the main JavaScript thread
immediately before garbage collection.
Values contained by a JsBox
must implement Finalize
.
§Examples
Finalize
provides a default implementation that does not perform any finalization.
struct Point(f64, f64);
impl Finalize for Point {}
A finalize
method may be specified for performing clean-up operations before dropping
the contained value.
struct Point(f64, f64);
impl Finalize for Point {
fn finalize<'a, C: Context<'a>>(self, cx: &mut C) {
let global = cx.global_object();
let emit: Handle<JsFunction> = global
.get(cx, "emit")
.unwrap();
let args = vec![
cx.string("gc_point").upcast::<JsValue>(),
cx.number(self.0).upcast(),
cx.number(self.1).upcast(),
];
emit.call(cx, global, args).unwrap();
}
}
Provided Methods§
Object Safety§
This trait is not object safe.