pub trait UserData: Any {
fn visit_references(&self, visit: &mut dyn FnMut(RawValue)) { ... }
}
Expand description
Marker trait for all user data types.
Due to limitations in Rust’s type system each user-defined type must implement this.
Provided Methods§
sourcefn visit_references(&self, visit: &mut dyn FnMut(RawValue))
fn visit_references(&self, visit: &mut dyn FnMut(RawValue))
Used to let the GC know of any RawValue
s referenced by the data.
Normally, referencing RawValue
s inside of user data is unsafe, because they may be
garbage collected at any time. There is no way for you to know whether a RawValue
has been collected or not.
So to allow the GC to see any RawValue
references inside user data, this must be
overridden. visit
should be called for each RawValue
stored inside the user data, so
that the GC can mark the references as reachable.
It’s usually better/easier to deal with strong Value
s which use
reference counting to manage allocations.
Examples
use mica::{UserData, ll::value::RawValue};
struct MyVec {
elements: Vec<RawValue>,
}
impl UserData for MyVec {
fn visit_references(&self, visit: &mut dyn FnMut(RawValue)) {
for &element in &self.elements {
visit(element);
}
}
}