Skip to main content

ProgressReporter

Trait ProgressReporter 

Source
pub trait ProgressReporter: Send + Sync {
    // Required methods
    fn set_message(&self, message: &str);
    fn set_progress(&self, current: u64, total: u64);
    fn finish_success(&self, message: &str);
    fn finish_error(&self, message: &str);

    // Provided method
    fn inc(&self, delta: u64) { ... }
}
Expand description

Trait for reporting progress during long-running operations.

This trait decouples the storage layer from the UI layer, allowing operations like S3 uploads to report progress without depending on typub-ui.

§Implementations

  • NullReporter - Discards all progress reports (default)
  • FnReporter - Wraps a closure for simple progress reporting
  • typub-ui provides IndicatifReporter with progress bars (Phase 4)

§Example

use typub_log::{ProgressReporter, NullReporter};

fn upload_with_progress(reporter: &dyn ProgressReporter) {
    reporter.set_message("Uploading assets...");
    for i in 0..10 {
        // ... upload logic ...
        reporter.set_progress(i + 1, 10);
    }
    reporter.finish_success("Upload complete");
}

// Use null reporter when no UI is available
upload_with_progress(&NullReporter);

Required Methods§

Source

fn set_message(&self, message: &str)

Set the current progress message.

Source

fn set_progress(&self, current: u64, total: u64)

Set progress as (current, total).

For indeterminate progress, call with (0, 0).

Source

fn finish_success(&self, message: &str)

Mark the operation as successfully completed.

Source

fn finish_error(&self, message: &str)

Mark the operation as failed.

Provided Methods§

Source

fn inc(&self, delta: u64)

Increment progress by a given amount.

Implementations on Foreign Types§

Source§

impl ProgressReporter for ()

Unit type implements ProgressReporter as a null reporter.

This allows passing &() when no progress reporting is needed.

Source§

fn set_message(&self, _message: &str)

Source§

fn set_progress(&self, _current: u64, _total: u64)

Source§

fn finish_success(&self, _message: &str)

Source§

fn finish_error(&self, _message: &str)

Implementors§