diff --git a/gc/src/gc_ref.rs b/gc/src/gc_ref.rs index 53f4a2d..14f1700 100644 --- a/gc/src/gc_ref.rs +++ b/gc/src/gc_ref.rs @@ -1,6 +1,6 @@ -use std::{ops::Deref, ptr::NonNull}; +use std::{marker::PhantomData, ops::Deref, ptr::NonNull}; -pub struct GcRef(pub(crate) NonNull); +pub struct GcRef(pub(crate) NonNull, PhantomData); impl Deref for GcRef { type Target = T; @@ -12,7 +12,7 @@ impl Deref for GcRef { impl GcRef { pub(crate) unsafe fn new(ptr: NonNull) -> Self { - Self(ptr) + Self(ptr, PhantomData) } /// # Safety diff --git a/gc/src/trace.rs b/gc/src/trace.rs index c2bc79f..0e5b57b 100644 --- a/gc/src/trace.rs +++ b/gc/src/trace.rs @@ -50,6 +50,17 @@ where } } +unsafe impl GCTrace for Option +where + T: GCTrace, +{ + fn trace(&self, t: &mut GCTracer) { + if let Some(ref v) = self { + v.trace(t); + } + } +} + unsafe impl GCTrace for () { fn trace(&self, _tracer: &mut GCTracer) {} }