Add a phantom ref to gc

This commit is contained in:
bad 2022-06-12 12:47:11 +02:00
parent 229cefe028
commit b4fc95c64b
2 changed files with 14 additions and 3 deletions

View file

@ -1,6 +1,6 @@
use std::{ops::Deref, ptr::NonNull};
use std::{marker::PhantomData, ops::Deref, ptr::NonNull};
pub struct GcRef<T>(pub(crate) NonNull<T>);
pub struct GcRef<T>(pub(crate) NonNull<T>, PhantomData<T>);
impl<T> Deref for GcRef<T> {
type Target = T;
@ -12,7 +12,7 @@ impl<T> Deref for GcRef<T> {
impl<T> GcRef<T> {
pub(crate) unsafe fn new(ptr: NonNull<T>) -> Self {
Self(ptr)
Self(ptr, PhantomData)
}
/// # Safety

View file

@ -50,6 +50,17 @@ where
}
}
unsafe impl<T> GCTrace for Option<T>
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) {}
}