pub struct ProgressRun<'a> { /* private fields */ }Expand description
Tracks one progress-producing operation and reports lifecycle events.
ProgressRun owns no operation-specific counters. Callers keep their own
domain state and pass freshly built ProgressCounters when reporting.
The run only manages elapsed time, periodic running-event throttling,
optional stage metadata, and forwarding immutable events to a reporter.
§Examples
use std::time::Duration;
use qubit_progress::{
NoOpProgressReporter,
ProgressCounters,
ProgressRun,
};
let reporter = NoOpProgressReporter;
let mut progress = ProgressRun::new(&reporter, Duration::from_secs(5));
progress.report_started(ProgressCounters::new(Some(2)));
let running = ProgressCounters::new(Some(2))
.with_completed_count(1)
.with_active_count(1);
let _reported = progress.report_running_if_due(running);
let finished = ProgressCounters::new(Some(2))
.with_completed_count(2)
.with_succeeded_count(2);
progress.report_finished(finished);Implementations§
Source§impl<'a> ProgressRun<'a>
impl<'a> ProgressRun<'a>
Sourcepub fn new(
reporter: &'a dyn ProgressReporter,
report_interval: Duration,
) -> Self
pub fn new( reporter: &'a dyn ProgressReporter, report_interval: Duration, ) -> Self
Sourcepub fn from_start(
reporter: &'a dyn ProgressReporter,
report_interval: Duration,
started_at: Instant,
) -> Self
pub fn from_start( reporter: &'a dyn ProgressReporter, report_interval: Duration, started_at: Instant, ) -> Self
Creates a progress run from an explicit start instant.
§Parameters
reporter- Reporter receiving progress events.report_interval- Minimum delay between due-based running events.started_at- Monotonic instant representing operation start.
§Returns
A progress run using started_at for elapsed-time calculations.
Sourcepub fn with_stage(self, stage: ProgressStage) -> Self
pub fn with_stage(self, stage: ProgressStage) -> Self
Sourcepub fn without_stage(self) -> Self
pub fn without_stage(self) -> Self
Sourcepub fn report_started(&self, counters: ProgressCounters)
pub fn report_started(&self, counters: ProgressCounters)
Sourcepub fn report_running(&self, counters: ProgressCounters)
pub fn report_running(&self, counters: ProgressCounters)
Sourcepub fn report_running_if_due(&mut self, counters: ProgressCounters) -> bool
pub fn report_running_if_due(&mut self, counters: ProgressCounters) -> bool
Reports a running lifecycle event if the configured interval has passed.
§Parameters
counters- Current counters for the operation.
§Returns
true when a running event was emitted, or false when the next
running-event deadline has not been reached.
§Panics
Propagates panics from the configured reporter when an event is due.
Sourcepub fn report_finished(&self, counters: ProgressCounters)
pub fn report_finished(&self, counters: ProgressCounters)
Sourcepub fn report_failed(&self, counters: ProgressCounters)
pub fn report_failed(&self, counters: ProgressCounters)
Sourcepub fn report_canceled(&self, counters: ProgressCounters)
pub fn report_canceled(&self, counters: ProgressCounters)
Sourcepub fn report(&self, phase: ProgressPhase, counters: ProgressCounters)
pub fn report(&self, phase: ProgressPhase, counters: ProgressCounters)
Sourcepub fn report_with_elapsed(
&self,
phase: ProgressPhase,
counters: ProgressCounters,
elapsed: Duration,
)
pub fn report_with_elapsed( &self, phase: ProgressPhase, counters: ProgressCounters, elapsed: Duration, )
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the elapsed duration since this run started.
§Returns
The monotonic elapsed duration for this progress run.
Sourcepub const fn started_at(&self) -> Instant
pub const fn started_at(&self) -> Instant
Returns the start instant for this run.
§Returns
The monotonic instant used as this run’s start time.
Sourcepub const fn report_interval(&self) -> Duration
pub const fn report_interval(&self) -> Duration
Returns the configured running-event interval.
§Returns
The minimum delay between due-based running events.
Sourcepub const fn stage(&self) -> Option<&ProgressStage>
pub const fn stage(&self) -> Option<&ProgressStage>
Returns the optional stage metadata attached to events.
§Returns
Some(stage) when stage metadata is configured, otherwise None.