Skip to main content

ProgressHandle

Trait ProgressHandle 

Source
pub trait ProgressHandle: Send + Sync {
    // Required methods
    fn inc(&self, delta: u64);
    fn set_message(&self, msg: &str);
    fn finish(&self, msg: Option<&str>);

    // Provided methods
    fn set_length(&self, _total: u64) { ... }
    fn set_position(&self, _position: u64) { ... }
}
Expand description

A handle to a single in-flight unit of work.

The engine calls finish exactly once when the work ends — whether it succeeded or failed — so an implementation can rely on finish to clear or finalize its display and should not leave a bar dangling if it is never called again.

Handles are Send + Sync: a single handle is shared by reference across the retried attempts of one download, and that download future must stay Send so callers can drive it from a multi-threaded runtime (e.g. tokio::spawn).

Required Methods§

Source

fn inc(&self, delta: u64)

Advances progress by delta units.

Source

fn set_message(&self, msg: &str)

Updates the displayed message for this unit of work.

Source

fn finish(&self, msg: Option<&str>)

Marks this unit of work complete, optionally with a final message. Called exactly once per handle, on both the success and failure paths.

Provided Methods§

Source

fn set_length(&self, _total: u64)

Sets (or updates) the total number of units when it only becomes known after the handle was created — e.g. a download’s Content-Length arriving with the response. Implementations that cannot re-total may ignore this; the default does nothing.

Source

fn set_position(&self, _position: u64)

Resets (overrides) the absolute progress position to position units.

Unlike inc, which advances relative to the current position, this sets it directly — used to rewind to zero when a download is retried so re-downloaded bytes are not double-counted and the bar cannot overshoot its total. Implementations that cannot re-position may ignore this; the default does nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§