pub use js::jsapi::JSTracer;
use std::mem;
pub unsafe trait JSTraceable {
unsafe fn trace(&self, trc: *mut JSTracer);
fn as_ptr(&self) -> *const JSTraceable where Self: Sized {
unsafe { mem::transmute(self as &JSTraceable) }
}
fn as_mut_ptr(&mut self) -> *mut JSTraceable where Self: Sized {
unsafe { mem::transmute(self as &mut JSTraceable) }
}
}
unsafe impl JSTraceable for String {
unsafe fn trace(&self, _trc: *mut JSTracer) {}
}
unsafe impl JSTraceable for usize {
unsafe fn trace(&self, _trc: *mut JSTracer) {}
}
unsafe impl JSTraceable for () {
unsafe fn trace(&self, _trc: *mut JSTracer) {}
}
unsafe impl<T> JSTraceable for Option<T> where T: JSTraceable {
unsafe fn trace(&self, trc: *mut JSTracer) {
if let Some(ref val) = *self {
val.trace(trc);
}
}
}
unsafe impl<T> JSTraceable for Vec<T> where T: JSTraceable {
unsafe fn trace(&self, trc: *mut JSTracer) {
for val in self {
val.trace(trc);
}
}
}