pub trait Trace: Any {
// Required method
fn trace(&self, collector: &mut Collector);
}
Expand description
Report references to other GC-managed objects to the collector.
This trait must be implemented by all types that are allocated within a
Heap
.
Failure to enumerate all edges in an instance will result in wacky – but still safe! – behavior: panics when attempting to access a collected object, accesses to a “wrong” object that’s been allocated in place of the old object, etc…
§Example
use safe_gc::{Collector, Gc, Trace};
struct List<T: Trace> {
value: Gc<T>,
prev: Option<Gc<List<T>>>,
next: Option<Gc<List<T>>>,
}
impl<T: Trace> Trace for List<T> {
fn trace(&self, collector: &mut Collector) {
collector.edge(self.value);
if let Some(prev) = self.prev {
collector.edge(prev);
}
if let Some(next) = self.next {
collector.edge(next);
}
}
}