pub struct Gc<T: Trace + ?Sized + 'static> { /* private fields */ }
Expand description
A garbage-collected pointer type over an immutable value.
Implementations§
source§impl<T: Trace + ?Sized> Gc<T>
impl<T: Trace + ?Sized> Gc<T>
sourcepub fn new_cyclic<F>(data_fn: F) -> Self
pub fn new_cyclic<F>(data_fn: F) -> Self
Constructs a new Gc<T>
while giving you a WeakGc<T>
to the allocation, to allow
constructing a T which holds a weak pointer to itself.
Since the new Gc<T>
is not fully-constructed until Gc<T>::new_cyclic
returns, calling
upgrade
on the weak reference inside the closure will fail and result
in a None
value.
sourcepub fn into_raw(this: Self) -> NonNull<GcBox<T>>
pub fn into_raw(this: Self) -> NonNull<GcBox<T>>
Consumes the Gc
, returning a wrapped raw pointer.
To avoid a memory leak, the pointer must be converted back to a Gc
using Gc::from_raw
.
sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Returns true
if the two Gc
s point to the same allocation.
sourcepub const unsafe fn from_raw(inner_ptr: NonNull<GcBox<T>>) -> Self
pub const unsafe fn from_raw(inner_ptr: NonNull<GcBox<T>>) -> Self
Constructs a Gc<T>
from a raw pointer.
The raw pointer must have been returned by a previous call to Gc<U>::into_raw
where U
must have the same size and alignment as T
.
§Safety
This function is unsafe because improper use may lead to memory corruption, double-free, or misbehaviour of the garbage collector.
Trait Implementations§
source§impl<T: Trace + ?Sized + Ord> Ord for Gc<T>
impl<T: Trace + ?Sized + Ord> Ord for Gc<T>
source§impl<T: Trace + ?Sized + PartialEq> PartialEq for Gc<T>
impl<T: Trace + ?Sized + PartialEq> PartialEq for Gc<T>
source§impl<T: Trace + ?Sized + PartialOrd> PartialOrd for Gc<T>
impl<T: Trace + ?Sized + PartialOrd> PartialOrd for Gc<T>
source§impl<T: Trace + ?Sized> Trace for Gc<T>
impl<T: Trace + ?Sized> Trace for Gc<T>
source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize
on this object and all
contained subobjects.