Trait mica::UserData

source ·
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§

Used to let the GC know of any RawValues referenced by the data.

Normally, referencing RawValues 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 Values 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);
        }
    }
}

Implementors§