Add a phantom ref to gc
This commit is contained in:
parent
229cefe028
commit
b4fc95c64b
2 changed files with 14 additions and 3 deletions
|
@ -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> {
|
impl<T> Deref for GcRef<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
@ -12,7 +12,7 @@ impl<T> Deref for GcRef<T> {
|
||||||
|
|
||||||
impl<T> GcRef<T> {
|
impl<T> GcRef<T> {
|
||||||
pub(crate) unsafe fn new(ptr: NonNull<T>) -> Self {
|
pub(crate) unsafe fn new(ptr: NonNull<T>) -> Self {
|
||||||
Self(ptr)
|
Self(ptr, PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
|
@ -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 () {
|
unsafe impl GCTrace for () {
|
||||||
fn trace(&self, _tracer: &mut GCTracer) {}
|
fn trace(&self, _tracer: &mut GCTracer) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue