Skip to main content

GcScope

Struct GcScope 

Source
pub struct GcScope<'s> { /* private fields */ }
Expand description

Handle to a GC scope, used to:

  1. reference the scope state
  2. manage lifetime of the scope, pop the scope when the handle is dropped

Methods from Deref<Target = GcScopeState<'s>>§

Source

pub fn partition_id(&self) -> GcPartitionId

Source

pub fn stack_id(&self) -> GcScopeStackId

Source

pub fn heap(&self) -> &GcHeap

Source

pub fn heap_mut(&mut self) -> &mut GcHeap

Source

pub fn depth(&self) -> u32

Source

pub fn count(&self) -> usize

Source

pub fn parent(&self) -> Option<(&GcScopeState<'_>, u32)>

get parent scope, and its level.

Source

pub fn alloc_local<T: GcNode>( &self, payload: T, ) -> Result<Gc<'s, T>, (GcError, T)>

alloc a local node in scope.

Examples found in repository?
examples/gc_node_usage.rs (line 33)
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 add_non_local(&self, node: NonNull<GcHead>) -> bool

Source

pub fn remove_node(&self, node: NonNull<GcHead>) -> bool

Remove a LOCAL node from this scope’s cache and clear its LOCAL flag.

This is the inverse of add_node: it undoes the LOCAL protection that was granted when the node was allocated in this scope. After this call, the node is no longer protected by this scope and will be traced by GC solely through other GC references.

Returns true if the node was found and removed from this scope’s cache. Returns false if the node was not in this scope’s cache (e.g., it was already promoted, or belongs to a different scope).

§Safety

The caller must ensure the node is still alive and valid. This method does NOT check whether the node is the current promote node; the caller (e.g., ScopedContext::throw) is responsible for ensuring the node is not the promote target.

Source

pub fn contains(&self, node: NonNull<GcHead>) -> bool

Source

pub fn promote_node_to( &self, node: NonNull<GcHead>, target: &GcScopeState<'_>, ) -> bool

Move a node from this scope’s cache to the target scope’s cache.

The node retains its LOCAL flag — it is simply transferred from one scope’s protection to another’s. This is used when a return value needs to be moved from a child scope to its parent scope before the child scope is destroyed.

Returns true if the node was found in this scope and moved. Returns false if the node was not in this scope’s cache (e.g., it is a root node, or already belongs to another scope).

Source

pub fn clear(&self)

Examples found in repository?
examples/gc_node_usage.rs (line 36)
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§

Source§

impl<'s> Debug for GcScope<'s>

Source§

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

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

impl<'s> Deref for GcScope<'s>

Source§

type Target = GcScopeState<'s>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'s> DerefMut for GcScope<'s>

Source§

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

Mutably dereferences the value.
Source§

impl<'s> Drop for GcScope<'s>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'s> !RefUnwindSafe for GcScope<'s>

§

impl<'s> !Send for GcScope<'s>

§

impl<'s> !Sync for GcScope<'s>

§

impl<'s> !UnwindSafe for GcScope<'s>

§

impl<'s> Freeze for GcScope<'s>

§

impl<'s> Unpin for GcScope<'s>

§

impl<'s> UnsafeUnpin for GcScope<'s>

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> 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, 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.