pub struct Gc<'gc, T: ?Sized + 'gc> { /* private fields */ }
Expand description
A garbage collected pointer to a type T. Implements Copy, and is implemented as a plain machine
pointer. You can only allocate Gc
pointers through a &Mutation<'gc>
inside an arena type,
and through “generativity” such Gc
pointers may not escape the arena they were born in or
be stored inside TLS. This, combined with correct Collect
implementations, means that Gc
pointers will never be dangling and are always safe to access.
Implementations§
source§impl<'gc, T: 'gc> Gc<'gc, T>
impl<'gc, T: 'gc> Gc<'gc, T>
source§impl<'gc, T: ?Sized + 'gc> Gc<'gc, T>
impl<'gc, T: ?Sized + 'gc> Gc<'gc, T>
sourcepub fn as_ref(self: Gc<'gc, T>) -> &'gc T
pub fn as_ref(self: Gc<'gc, T>) -> &'gc T
Obtains a long-lived reference to the contents of this Gc
.
Unlike AsRef
or Deref
, the returned reference isn’t bound to the Gc
itself, and
will stay valid for the entirety of the current arena callback.
pub fn downgrade(this: Gc<'gc, T>) -> GcWeak<'gc, T>
sourcepub fn write(mc: &Mutation<'gc>, gc: Self) -> &'gc Write<T>
pub fn write(mc: &Mutation<'gc>, gc: Self) -> &'gc Write<T>
Triggers a write barrier on this Gc
, allowing for further safe mutation.
sourcepub fn ptr_eq(this: Gc<'gc, T>, other: Gc<'gc, T>) -> bool
pub fn ptr_eq(this: Gc<'gc, T>, other: Gc<'gc, T>) -> bool
Returns true if two Gc
s point to the same allocation.
Similarly to Rc::ptr_eq
and Arc::ptr_eq
, this function ignores the metadata of dyn
pointers.
pub fn as_ptr(gc: Gc<'gc, T>) -> *const T
sourcepub fn is_dead(_: &Finalization<'gc>, gc: Gc<'gc, T>) -> bool
pub fn is_dead(_: &Finalization<'gc>, gc: Gc<'gc, T>) -> bool
Returns true when a pointer is dead during finalization. This is equivalent to
GcWeak::is_dead
for strong pointers.
Any strong pointer reachable from the root will never be dead, BUT there can be strong pointers reachable only through other weak pointers that can be dead.
sourcepub fn resurrect(fc: &Finalization<'gc>, gc: Gc<'gc, T>)
pub fn resurrect(fc: &Finalization<'gc>, gc: Gc<'gc, T>)
Manually marks a dead Gc
pointer as reachable and keeps it alive.
Equivalent to GcWeak::resurrect
for strong pointers. Manually marks this pointer and
all transitively held pointers as reachable, thus keeping them from being dropped this
collection cycle.
source§impl<'gc, T: ?Sized + 'gc> Gc<'gc, RefLock<T>>
impl<'gc, T: ?Sized + 'gc> Gc<'gc, RefLock<T>>
pub fn borrow(self) -> Ref<'gc, T>
pub fn try_borrow(self) -> Result<Ref<'gc, T>, BorrowError>
pub fn borrow_mut(self, mc: &Mutation<'gc>) -> RefMut<'gc, T>
pub fn try_borrow_mut( self, mc: &Mutation<'gc> ) -> Result<RefMut<'gc, T>, BorrowMutError>
Trait Implementations§
source§impl<'gc, T: ?Sized + 'gc> Collect for Gc<'gc, T>
impl<'gc, T: ?Sized + 'gc> Collect for Gc<'gc, T>
source§fn trace(&self, cc: &Collection)
fn trace(&self, cc: &Collection)
Collect::trace
on all held Gc
pointers. If this type holds inner types that
implement Collect
, a valid implementation would simply call Collect::trace
on all the
held values to ensure this.source§fn needs_trace() -> boolwhere
Self: Sized,
fn needs_trace() -> boolwhere
Self: Sized,
Gc
pointer and trace
is unnecessary
to call, you may implement this method and return false. The default implementation returns
true, signaling that Collect::trace
must be called.source§impl<'gc, T: Ord + ?Sized + 'gc> Ord for Gc<'gc, T>
impl<'gc, T: Ord + ?Sized + 'gc> Ord for Gc<'gc, T>
source§impl<'gc, T: PartialOrd + ?Sized + 'gc> PartialOrd for Gc<'gc, T>
impl<'gc, T: PartialOrd + ?Sized + 'gc> PartialOrd for Gc<'gc, T>
source§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
self
and other
) and is used by the <=
operator. Read more