use core::cell::{Cell, RefCell};
pub unsafe trait GcTrace {
fn trace(&self);
#[inline]
fn size_hint(&self) -> usize { 0 }
fn cleanup(&self) { }
}
unsafe impl<T> GcTrace for [T] where T: GcTrace {
fn trace(&self) {
for item in self.iter() {
item.trace()
}
}
fn size_hint(&self) -> usize {
self.iter().map(GcTrace::size_hint).sum()
}
}
unsafe impl<T> GcTrace for Cell<T> where T: GcTrace + Copy {
fn trace(&self) {
self.get().trace()
}
fn size_hint(&self) -> usize {
self.get().size_hint()
}
}
unsafe impl<T> GcTrace for RefCell<T> where T: GcTrace {
fn trace(&self) {
self.borrow().trace()
}
fn size_hint(&self) -> usize {
self.borrow().size_hint()
}
}