> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/relay/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server.

# Struct Scope Stack

> Mutable stack of active scopes plus their scope-local registries.

Generated from `cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker`.

```rust
pub struct ScopeStack { /* private fields */ }
```

Mutable stack of active scopes plus their scope-local registries.

The stack always contains an implicit root scope. Additional scopes are pushed as the public API opens lifecycle spans and removed when those spans close.

## Implementations

### `impl ScopeStack`

<pre />

#### `new`

<pre />

Create a new scope stack containing only the implicit root scope.

##### Returns

A [`ScopeStack`](/reference/api/rust-library-reference/nemo-relay/api/runtime/scope_stack/struct-scopestack) initialized with a single root scope and no scope-local registries.

#### `push`

<pre />

Push a scope handle onto the top of the stack.

##### Parameters

* `handle`: Scope handle to make the new top-most active scope.

#### `top`

<pre />

Return the current top-most scope handle.

##### Returns

A shared reference to the active scope at the top of the stack.

##### Notes

This function never returns `None` because the implicit root scope is always present.

#### `top_mut`

<pre />

Return the current top-most scope handle mutably.

##### Returns

A mutable reference to the active scope at the top of the stack.

#### `root_uuid`

<pre />

Return the UUID of the implicit root scope.

##### Returns

The stable UUID of the root scope stored at the bottom of the stack.

#### `scopes`

<pre />

Return the full ordered stack of scope handles.

##### Returns

A slice of scopes ordered from root to the current top-most scope.

#### `find`

<pre />

Find a scope handle by UUID.

##### Parameters

* `uuid`: UUID of the scope to search for.

##### Returns

`Some(&ScopeHandle)` when the scope is active on this stack and `None` otherwise.

#### `remove`

<pre />

Remove the current top scope if it matches `uuid`.

##### Parameters

* `uuid`: UUID of the scope expected to be at the top of the stack.

##### Returns

A [`Result`](/reference/api/rust-library-reference/nemo-relay/error/type-result) containing the removed [`ScopeHandle`](/reference/api/rust-library-reference/nemo-relay/api/scope/struct-scopehandle).

##### Errors

Returns [`FlowError::InvalidArgument`](/reference/api/rust-library-reference/nemo-relay/error/enum-flowerror) when the scope exists but is not the current top of the stack or when the caller attempts to remove the implicit root scope. Returns [`FlowError::NotFound`](/reference/api/rust-library-reference/nemo-relay/error/enum-flowerror) when the UUID is not present on the stack.

## Trait Implementations

### `impl Debug for ScopeStack`

<pre />

#### `fmt`

<pre />

### `impl Default for ScopeStack`

<pre />

#### `default`

<pre />