pub struct Gc<T: ?Sized> { /* private fields */ }Expand description
A GC-managed pointer. Copy + Clone (one-machine-word). Replaces GcRef<T>.
Implementations§
Source§impl<T: Trace + 'static> Gc<T>
impl<T: Trace + 'static> Gc<T>
Sourcepub fn new_uncollected(value: T) -> Self
pub fn new_uncollected(value: T) -> Self
Allocate a GcBox<T> outside any heap registry: a deliberate escape
hatch for the rare detached/process-lifetime case. The returned
Gc<T> is reachable only through the caller’s own retention path;
without joining a heap owner list, it will never be swept (so
effectively leaks until process exit — same as Rc behavior).
Sourcepub fn as_trace_ptr(self) -> NonNull<GcBox<dyn Trace>>
pub fn as_trace_ptr(self) -> NonNull<GcBox<dyn Trace>>
Erased heap-list pointer for collector-owned intrusive bookkeeping.
Source§impl<T: ?Sized> Gc<T>
impl<T: ?Sized> Gc<T>
Sourcepub fn ptr_eq(a: Self, b: Self) -> bool
pub fn ptr_eq(a: Self, b: Self) -> bool
Two Gc<T>s are identity-equal iff they point at the same box.
Sourcepub fn identity(self) -> usize
pub fn identity(self) -> usize
Identity as a usize — usable as a hash table key for “is the same object” lookups.
Sourcepub fn is_heap_tracked(self) -> bool
pub fn is_heap_tracked(self) -> bool
True iff this box is linked into a sweepable heap owner list
(HDR_COLLECTED set) — the collector may free it during the owning
heap’s lifetime. Detached (new_uncollected) boxes and heap-owned
bootstrap (allocate_uncollected) boxes report false.
Sourcepub fn is_heap_owned(self) -> bool
pub fn is_heap_owned(self) -> bool
True iff some Heap will free this box — during collection
(allocate) or at teardown in drop_all (allocate_uncollected).
Only detached Gc::new_uncollected boxes report false. Strict-guard
mode keys on this: a guard-less weak handle or dropped buffer charge
is hazardous for any heap-owned box (a bootstrap box’s weak handle
dangles after heap teardown just the same), while the detached
process-lifetime path is the sanctioned legacy behavior.
pub fn color(self) -> Color
pub fn set_color(self, color: Color)
pub fn age(self) -> GcAge
pub fn set_age(self, age: GcAge)
pub fn is_finalized(self) -> bool
pub fn set_finalized(self, finalized: bool)
Sourcepub fn account_buffer(&self, heap: &Heap, delta: isize)
pub fn account_buffer(&self, heap: &Heap, delta: isize)
Charge (delta > 0) or refund (delta < 0) delta bytes of this
object’s owned heap buffers against the pacer, keeping header.size
as the single source of truth for what sweep will refund.
No-op when delta == 0 or when this box is not on a heap owner list
(collected == false): an uncollected box is never swept, so charging
it would permanently inflate the byte counter. On the collected path,
header.size and the heap’s byte counter move together, so after sweep
frees this box it refunds exactly the bytes that were charged here.
Trait Implementations§
impl<T: ?Sized> Copy for Gc<T>
impl<T: ?Sized> Eq for Gc<T>
Source§impl<T: Trace + 'static> Trace for Gc<T>
Gc<T> is itself traceable: marking it forwards to the contained T.
impl<T: Trace + 'static> Trace for Gc<T>
Gc<T> is itself traceable: marking it forwards to the contained T.
fn trace(&self, m: &mut Marker)
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Heap::type_name_count). Collector behavior must not branch on
this. The default covers container blanket impls, which are never
GC-boxed directly; concrete runtime types override it with
std::any::type_name::<Self>().