pub struct GcRef<T: Trace + 'static>(pub Gc<T>);Expand description
A GC-managed pointer to a Lua collectable object. Newtype over
lua_gc::Gc<T> so callers preserve gc.0-shape access while the
backend swaps under them.
Tuple Fields§
§0: Gc<T>Implementations§
Source§impl<T: Trace + 'static> GcRef<T>
impl<T: Trace + 'static> GcRef<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Allocate a new GC-tracked value. If a HeapGuard is active (set by
state.run() / pcall_k), the new allocation joins that heap’s
allgc chain. Otherwise it allocates “uncollected” — leaks until
process exit, same as the old Rc::new behavior.
Sourcepub fn trace_obj(&self, m: &mut Marker)
pub fn trace_obj(&self, m: &mut Marker)
Cycle-aware trace dispatch.
During D-0/D-1 (before a real Color::Gray flag is reachable from
inside Trace impls), Marker::try_visit records the underlying
allocation’s identity and short-circuits a second recursion. Once
D-2 ships the in-header color flag, this helper collapses to
m.mark(self.0).
Source§impl<T: Trace + 'static> GcRef<T>
impl<T: Trace + 'static> GcRef<T>
Sourcepub fn ptr_eq(a: &Self, b: &Self) -> bool
pub fn ptr_eq(a: &Self, b: &Self) -> bool
Two GcRefs are identity-equal iff they point at the same box.
Sourcepub fn identity(&self) -> usize
pub fn identity(&self) -> usize
Identity as a usize — used as a HashMap key for “same object” tests.
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Number of strong references. Phase D-1: always returns 1 (no refcount semantics). Real value once weak refs land in D-2.
Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Number of weak references. Phase D-1: always returns 0.
Trait Implementations§
Source§impl<T: Trace + 'static> Trace for GcRef<T>
Forwarder for GcRef<T>. Now that GcRef wraps a real lua_gc::Gc<T>
(D-1e), tracing must enqueue the box onto the gray queue via
Marker::mark — that is what flips its header color from White to Gray
and ultimately to Black during gray-queue drainage. The previous
try_visit short-circuit was a Phase A-D-0 workaround for the
Rc-backed handle (no header, no color), and produced a silent bug
post-D-1e: every GC-tracked allocation stayed White and was freed in
the sweep on the first collectgarbage(). Cycles are now handled
natively by the heap’s gray-queue (Color::Gray check in mark makes
re-visits idempotent).
impl<T: Trace + 'static> Trace for GcRef<T>
Forwarder for GcRef<T>. Now that GcRef wraps a real lua_gc::Gc<T>
(D-1e), tracing must enqueue the box onto the gray queue via
Marker::mark — that is what flips its header color from White to Gray
and ultimately to Black during gray-queue drainage. The previous
try_visit short-circuit was a Phase A-D-0 workaround for the
Rc-backed handle (no header, no color), and produced a silent bug
post-D-1e: every GC-tracked allocation stayed White and was freed in
the sweep on the first collectgarbage(). Cycles are now handled
natively by the heap’s gray-queue (Color::Gray check in mark makes
re-visits idempotent).