Skip to main content

ProgressSink

Trait ProgressSink 

Source
pub trait ProgressSink:
    Send
    + Sync
    + 'static {
    // Required methods
    fn report(&self, stage: &str, current: usize, total: usize);
    fn start_stage(&self, name: &str);
    fn complete_stage(&self, name: &str);
    fn warn(&self, message: &str);
    fn child(&self, prefix: &str) -> Arc<dyn ProgressSink>;
}
Expand description

Progress sink abstraction - receives progress updates.

Implementations handle progress visualization (TUI, CLI, logging). All methods should be cheap - expensive work should be deferred.

§Implementation Requirements

  • All methods must be non-blocking
  • Methods may be called from multiple threads concurrently
  • Methods should not panic on invalid input (e.g., current > total)
  • The child method should return a sink that prefixes stage names

§Method Costs

MethodExpected Cost
reportO(1), minimal allocation
start_stageO(1), may log or update UI
complete_stageO(1), may log or update UI
warnO(1), may log
childO(1), creates new Arc

Required Methods§

Source

fn report(&self, stage: &str, current: usize, total: usize)

Report progress for a named stage.

§Arguments
  • stage - The name of the current stage
  • current - The current progress count (0-indexed)
  • total - The total number of items
§Example
sink.report("File Analysis", 42, 100);  // 42/100 files processed
Source

fn start_stage(&self, name: &str)

Report a sub-stage starting.

This is called at the beginning of a stage. Implementations may:

  • Display a message
  • Start a timer
  • Initialize UI elements
§Arguments
  • name - The name of the stage being started
Source

fn complete_stage(&self, name: &str)

Report a stage completing.

This is called when a stage finishes (successfully or with error). Implementations should clean up any resources started in start_stage.

§Arguments
  • name - The name of the stage that completed
Source

fn warn(&self, message: &str)

Report a warning without interrupting progress.

Warnings should be displayed in a way that doesn’t disrupt the progress display. For example:

  • Log to a separate area in TUI
  • Print to stderr in CLI mode
  • Collect for later display
§Arguments
  • message - The warning message
Source

fn child(&self, prefix: &str) -> Arc<dyn ProgressSink>

Create a child sink for nested progress.

Child sinks are used for nested stages. The child should prefix stage names with the provided prefix for context.

§Arguments
  • prefix - A prefix to prepend to stage names
§Returns

A new progress sink that prefixes stage names

Implementors§