Skip to main content

Gc

Struct Gc 

Source
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:

Implementations§

Source§

impl<'a, T: GcNode> Gc<'a, T>

Source

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.

Source

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}
Source

pub fn as_raw(&self) -> &GcRef<T>

Access the raw GcRef without consuming self.

Trait Implementations§

Source§

impl<'a, T: GcNode> Clone for Gc<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: GcNode> Copy for Gc<'a, T>

Source§

impl<'a, T: GcNode> Debug for Gc<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: GcNode> Deref for Gc<'a, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T: GcNode> DerefMut for Gc<'a, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a, T: GcNode> Eq for Gc<'a, T>

Source§

impl<'a, T: GcNode> PartialEq for Gc<'a, T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.