pub struct Gc<'a, T: GcNode> { /* private fields */ }Expand description
A safe GC reference with a lifetime guarantee.
Gc<'a, T> wraps a GcRef<T> and provides safe Deref/DerefMut
implementations, where the lifetime 'a proves that the GC object is
alive and protected (e.g., by a scope or a heap borrow).
§Safety invariant
The lifetime 'a must be derived from a source that guarantees the
GC object will not be collected during 'a. Typical sources:
- A
GcScopeorGcScopeStatefor scope-local allocations - A
&GcHeapborrow forGcWeak::upgraderesults
Implementations§
Source§impl<'a, T: GcNode> Gc<'a, T>
impl<'a, T: GcNode> Gc<'a, T>
Sourcepub unsafe fn from_raw(inner: GcRef<T>) -> Self
pub unsafe fn from_raw(inner: GcRef<T>) -> Self
Create a Gc from a raw GcRef and a lifetime proof.
§Safety
The caller must ensure that the object referenced by inner stays
alive for the entire lifetime 'a. This is typically guaranteed
by tying 'a to a scope or a heap borrow.
Sourcepub fn into_raw(self) -> GcRef<T>
pub fn into_raw(self) -> GcRef<T>
Convert back to the raw GcRef handle.
Examples found in repository?
examples/gc_node_usage.rs (line 35)
26fn alloc_static(
27 heap: &mut GcHeap,
28 stack_id: GcScopeStackId,
29 value: i32,
30) -> GcResult<GcRef<StaticNode>> {
31 heap.with_new_scope(stack_id, |ctx| {
32 let r = ctx
33 .alloc_local(StaticNode { _value: value })
34 .map_err(|(err, _)| err)
35 .map(|gc| gc.into_raw());
36 ctx.clear();
37 r
38 })
39}
40
41fn alloc_other(
42 heap: &mut GcHeap,
43 stack_id: GcScopeStackId,
44 value: i32,
45) -> GcResult<GcRef<OtherNode>> {
46 heap.with_new_scope(stack_id, |ctx| {
47 let r = ctx
48 .alloc_local(OtherNode { _value: value })
49 .map_err(|(err, _)| err)
50 .map(|gc| gc.into_raw());
51 ctx.clear();
52 r
53 })
54}Trait Implementations§
impl<'a, T: GcNode> Copy for Gc<'a, T>
impl<'a, T: GcNode> Eq for Gc<'a, T>
Auto Trait Implementations§
impl<'a, T> !Send for Gc<'a, T>
impl<'a, T> !Sync for Gc<'a, T>
impl<'a, T> Freeze for Gc<'a, T>
impl<'a, T> RefUnwindSafe for Gc<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Unpin for Gc<'a, T>where
T: Unpin,
impl<'a, T> UnsafeUnpin for Gc<'a, T>
impl<'a, T> UnwindSafe for Gc<'a, T>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more