Skip to content

Commit 3e026b3

Browse files
committed
Implement GcErase + GcRebrand for GcCell
Add #[zerogc(collector_id(SimpleCollectorId))] annotation to the binary_trees example.
1 parent f3b7556 commit 3e026b3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

libs/simple/examples/binary_trees.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
arbitrary_self_types, // Unfortunately this is required for methods on Gc refs
33
)]
44
use zerogc::prelude::*;
5-
use zerogc_simple::{SimpleCollector, SimpleCollectorContext, Gc};
5+
use zerogc_simple::{SimpleCollector, SimpleCollectorContext, Gc, CollectorId as SimpleCollectorId};
66
use zerogc_derive::Trace;
77

88
use slog::{Logger, Drain, o};
99

1010
#[derive(Trace)]
11+
#[zerogc(collector_id(SimpleCollectorId))]
1112
struct Tree<'gc> {
1213
#[zerogc(mutable(public))]
1314
children: GcCell<Option<(Gc<'gc, Tree<'gc>>, Gc<'gc, Tree<'gc>>)>>,

src/cell.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! and it'll generate a safe wrapper.
1616
use core::cell::Cell;
1717

18-
use crate::{GcSafe, Trace, GcVisitor, NullTrace, TraceImmutable, GcDirectBarrier,};
18+
use crate::{GcSafe, Trace, GcVisitor, NullTrace, TraceImmutable, GcDirectBarrier, CollectorId, GcErase, GcRebrand};
1919

2020
/// A `Cell` pointing to a garbage collected object.
2121
///
@@ -104,3 +104,13 @@ unsafe impl<T: GcSafe + Copy> GcSafe for GcCell<T> {
104104
/// Since T is Copy, we shouldn't need to be dropped
105105
const NEEDS_DROP: bool = false;
106106
}
107+
unsafe impl<'min, T, Id> GcErase<'min, Id> for GcCell<T>
108+
where T: Trace + Copy + GcErase<'min, Id>, Id: CollectorId,
109+
T::Erased: Copy + Trace {
110+
type Erased = GcCell<T::Erased>;
111+
}
112+
unsafe impl<'new_gc, T, Id> GcRebrand<'new_gc, Id> for GcCell<T>
113+
where T: Trace + Copy + GcRebrand<'new_gc, Id>, Id: CollectorId,
114+
T::Branded: Copy + Trace {
115+
type Branded = GcCell<T::Branded>;
116+
}

0 commit comments

Comments
 (0)