pub struct Progress { /* private fields */ }Expand description
A thread-safe, cloneable handle to a progress indicator.
Progress separates “hot” data (position, total, finished status) which are stored in
atomics for high-performance updates, from “cold” data (names, errors, timing) which are
guarded by an RwLock.
Cloning a Progress is cheap (Arc bump) and points to the same underlying state.
Implementations§
Source§impl Progress
impl Progress
Sourcepub fn new(
kind: ProgressType,
name: impl Into<CompactString>,
total: impl Into<u64>,
) -> Self
pub fn new( kind: ProgressType, name: impl Into<CompactString>, total: impl Into<u64>, ) -> Self
Creates a new Progress instance.
§Parameters
kind: The type of indicator.name: A label for the task.total: The total expected count (use 0 for spinners).
Sourcepub fn new_pb(name: impl Into<CompactString>, total: impl Into<u64>) -> Self
pub fn new_pb(name: impl Into<CompactString>, total: impl Into<u64>) -> Self
Creates a new generic progress bar with a known total.
Sourcepub fn new_spinner(name: impl Into<CompactString>) -> Self
pub fn new_spinner(name: impl Into<CompactString>) -> Self
Creates a new spinner (indeterminate progress).
Sourcepub fn get_name(&self) -> CompactString
pub fn get_name(&self) -> CompactString
Gets the current name/label of the progress task.
Sourcepub fn set_name(&self, name: impl Into<CompactString>)
pub fn set_name(&self, name: impl Into<CompactString>)
Updates the name/label of the progress task.
Sourcepub fn get_item(&self) -> CompactString
pub fn get_item(&self) -> CompactString
Gets the current item description (e.g., currently processing file).
Sourcepub fn set_item(&self, item: impl Into<CompactString>)
pub fn set_item(&self, item: impl Into<CompactString>)
Updates the current item description.
Sourcepub fn get_error(&self) -> Option<CompactString>
pub fn get_error(&self) -> Option<CompactString>
Returns the error message, if one occurred.
Sourcepub fn set_error(&self, error: Option<impl Into<CompactString>>)
pub fn set_error(&self, error: Option<impl Into<CompactString>>)
Sets (or clears) an error message for this task.
Sourcepub fn inc(&self, amount: impl Into<u64>)
pub fn inc(&self, amount: impl Into<u64>)
Increments the progress position by the specified amount.
This uses Ordering::Relaxed for maximum performance.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Checks if the task is marked as finished.
Sourcepub fn set_finished(&self, finished: bool)
pub fn set_finished(&self, finished: bool)
Manually sets the finished state.
Prefer using finish, finish_with_item,
or finish_with_error to ensure timestamps are recorded.
Sourcepub fn get_elapsed(&self) -> Option<Duration>
pub fn get_elapsed(&self) -> Option<Duration>
Calculates the duration elapsed since creation.
If the task is finished, this returns the duration between start and finish.
If never started (no start time recorded), returns None.
Sourcepub fn get_percent(&self) -> f64
pub fn get_percent(&self) -> f64
Returns the current completion percentage (0.0 to 100.0).
Returns 0.0 if total is zero.
Sourcepub fn finish_with_item(&self, item: impl Into<CompactString>)
pub fn finish_with_item(&self, item: impl Into<CompactString>)
Sets the current item and marks the task as finished.
Sourcepub fn finish_with_error(&self, error: impl Into<CompactString>)
pub fn finish_with_error(&self, error: impl Into<CompactString>)
Sets an error message and marks the task as finished.
Sourcepub fn atomic_pos(&self) -> Arc<AtomicU64>
pub fn atomic_pos(&self) -> Arc<AtomicU64>
Returns a shared reference to the atomic position counter.
Useful for sharing this specific counter with other systems.
Sourcepub fn atomic_total(&self) -> Arc<AtomicU64>
pub fn atomic_total(&self) -> Arc<AtomicU64>
Returns a shared reference to the atomic total counter.
Sourcepub fn snapshot(&self) -> ProgressSnapshot
pub fn snapshot(&self) -> ProgressSnapshot
Creates a consistent snapshot of the current state.
This involves acquiring a read lock on the “cold” data.