pub struct GcScope<'s> { /* private fields */ }Expand description
Handle to a GC scope, used to:
- reference the scope state
- manage lifetime of the scope, pop the scope when the handle is dropped
Methods from Deref<Target = GcScopeState<'s>>§
pub fn partition_id(&self) -> GcPartitionId
pub fn stack_id(&self) -> GcScopeStackId
pub fn heap(&self) -> &GcHeap
pub fn heap_mut(&mut self) -> &mut GcHeap
pub fn depth(&self) -> u32
pub fn count(&self) -> usize
Sourcepub fn parent(&self) -> Option<(&GcScopeState<'_>, u32)>
pub fn parent(&self) -> Option<(&GcScopeState<'_>, u32)>
get parent scope, and its level.
Sourcepub fn alloc_local<T: GcNode>(
&self,
payload: T,
) -> Result<Gc<'s, T>, (GcError, T)>
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?
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}pub fn add_non_local(&self, node: NonNull<GcHead>) -> bool
Sourcepub fn remove_node(&self, node: NonNull<GcHead>) -> bool
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.
pub fn contains(&self, node: NonNull<GcHead>) -> bool
Sourcepub fn promote_node_to(
&self,
node: NonNull<GcHead>,
target: &GcScopeState<'_>,
) -> bool
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).
Sourcepub fn clear(&self)
pub fn clear(&self)
Examples found in repository?
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}