> ## Documentation Index
> Fetch the complete documentation index at: https://desme.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ui_debug

> Mark a struct or enum as a data node visible in the dbgflow graph.

The `#[ui_debug]` attribute macro turns a struct or enum into a UI-visible data node. Annotated types appear in the browser graph with a `db` badge and can emit snapshots of their state at any point during execution. Snapshots are displayed in the node details panel alongside the sequence of traced function calls.

## Usage

Add `#[ui_debug]` above any `struct` or `enum` definition:

```rust theme={null}
use dbgflow::prelude::*;

#[ui_debug]
struct Pipeline {
    stage: String,
    items: Vec<String>,
}
```

```rust theme={null}
use dbgflow::prelude::*;

#[ui_debug]
enum Status {
    Pending,
    Running { attempt: usize },
    Done,
}
```

> [!NOTE]
>
> `#[ui_debug]` automatically derives `Debug` on your type if it is not already present. You do not need to add `#[derive(Debug)]` separately.

## Arguments

**name** `string`

Optional display label shown in the browser UI. Defaults to the type name as written in source.

```rust theme={null}
#[ui_debug(name = "Pipeline State")]
struct PipelineState {
    input: String,
    tokens: Vec<String>,
}
```

## The `emit_snapshot` method

Annotating a type with `#[ui_debug]` adds an `emit_snapshot` method to every instance of that type. Call it at any point to capture the current state of the value and attach it to the active session:

```rust theme={null}
value.emit_snapshot("label");
```

The `label` argument is a short string that identifies what was happening at the time of the snapshot. It appears as the snapshot title in the UI's output panel for the enclosing traced function.

## Example

The following example shows a struct with snapshot emissions inside a traced function:

```rust theme={null}
use dbgflow::prelude::*;

#[ui_debug(name = "Pipeline State")]
struct PipelineState {
    input: String,
    tokens: Vec<String>,
    verdict: Option<String>,
}

#[trace(name = "Ingest Input")]
fn ingest(state: &mut PipelineState) {
    state.tokens = state.input.split_whitespace().map(str::to_owned).collect();
    state.emit_snapshot("input tokenized");
}

#[trace(name = "Evaluate Verdict")]
fn evaluate(state: &mut PipelineState) {
    state.verdict = Some(if state.tokens.contains(&"ok".to_owned()) {
        "passed".to_owned()
    } else {
        "failed".to_owned()
    });
    state.emit_snapshot("verdict computed");
}

fn main() {
    dbgflow::capture_and_serve("pipeline", "127.0.0.1", 3000, || {
        let mut state = PipelineState {
            input: "hello ok world".to_owned(),
            tokens: Vec::new(),
            verdict: None,
        };
        ingest(&mut state);
        evaluate(&mut state);
    }).unwrap();
}
```

Each `emit_snapshot` call produces a `value_snapshot` event in the session. In the browser UI, these appear in the output section of the enclosing traced function node, in the order they were emitted.

## Using `#[ui_debug]` on enums

Enums are supported exactly like structs. All variants are captured through `Debug` formatting:

```rust theme={null}
use dbgflow::prelude::*;

#[ui_debug]
enum FetchResult {
    Success { body: String },
    Retry { attempts_left: usize },
    Failure(String),
}

#[trace]
fn fetch(result: &mut FetchResult) {
    *result = FetchResult::Retry { attempts_left: 2 };
    result.emit_snapshot("retrying");
}
```

> [!WARNING]
>
> `emit_snapshot` is only available on values of the annotated type — not on references. If you hold a `&mut T`, call `value.emit_snapshot(...)` directly on the mutable binding, not through a re-borrow.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.