Progress

Struct Progress 

Source
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

Source

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).
Source

pub fn new_pb(name: impl Into<CompactString>, total: impl Into<u64>) -> Self

Creates a new generic progress bar with a known total.

Source

pub fn new_spinner(name: impl Into<CompactString>) -> Self

Creates a new spinner (indeterminate progress).

Source

pub fn get_name(&self) -> CompactString

Gets the current name/label of the progress task.

Source

pub fn set_name(&self, name: impl Into<CompactString>)

Updates the name/label of the progress task.

Source

pub fn get_item(&self) -> CompactString

Gets the current item description (e.g., currently processing file).

Source

pub fn set_item(&self, item: impl Into<CompactString>)

Updates the current item description.

Source

pub fn get_error(&self) -> Option<CompactString>

Returns the error message, if one occurred.

Source

pub fn set_error(&self, error: Option<impl Into<CompactString>>)

Sets (or clears) an error message for this task.

Source

pub fn inc(&self, amount: impl Into<u64>)

Increments the progress position by the specified amount.

This uses Ordering::Relaxed for maximum performance.

Source

pub fn bump(&self)

Increments the progress position by 1.

Source

pub fn get_pos(&self) -> u64

Gets the current position.

Source

pub fn set_pos(&self, pos: u64)

Sets the absolute position.

Source

pub fn get_total(&self) -> u64

Gets the total target count.

Source

pub fn set_total(&self, total: u64)

Updates the total target count.

Source

pub fn is_finished(&self) -> bool

Checks if the task is marked as finished.

Source

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.

Source

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.

Source

pub fn get_percent(&self) -> f64

Returns the current completion percentage (0.0 to 100.0).

Returns 0.0 if total is zero.

Source

pub fn finish(&self)

Marks the task as finished and records the stop time.

Source

pub fn finish_with_item(&self, item: impl Into<CompactString>)

Sets the current item and marks the task as finished.

Source

pub fn finish_with_error(&self, error: impl Into<CompactString>)

Sets an error message and marks the task as finished.

Source

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.

Source

pub fn atomic_total(&self) -> Arc<AtomicU64>

Returns a shared reference to the atomic total counter.

Source

pub fn snapshot(&self) -> ProgressSnapshot

Creates a consistent snapshot of the current state.

This involves acquiring a read lock on the “cold” data.

Trait Implementations§

Source§

impl Clone for Progress

Source§

fn clone(&self) -> Progress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<&Progress> for ProgressSnapshot

Source§

fn from(progress: &Progress) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.