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) {
cx.global_object()
.method(cx.cx_mut(), "emit").unwrap()
.args(("gc_point", self.0, self.1)).unwrap()
.exec().unwrap();
}
}
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.