Struct ProgressBar
struct ProgressBar { ... }
A progress bar or spinner
The progress bar is an Arc around its internal state. When the progress bar is cloned it
just increments the refcount (so the original and its clone share the same state).
Implementations
impl ProgressBar
fn new(len: u64) -> SelfCreates a new progress bar with a given length
This progress bar by default draws directly to stderr, and refreshes a maximum of 20 times a second. To change the refresh rate, set the draw target to one with a different refresh rate.
fn no_length() -> SelfCreates a new progress bar without a specified length
This progress bar by default draws directly to stderr, and refreshes a maximum of 20 times a second. To change the refresh rate, set the draw target to one with a different refresh rate.
Creates a completely hidden progress bar
This progress bar still responds to API changes but it does not have a length or render in any way.
fn with_draw_target(len: Option<u64>, draw_target: ProgressDrawTarget) -> SelfCreates a new progress bar with a given length and draw target
fn style(self: &Self) -> ProgressStyleGet a clone of the current progress bar style.
fn with_style(self: Self, style: ProgressStyle) -> SelfA convenience builder-like function for a progress bar with a given style
fn with_tab_width(self: Self, tab_width: usize) -> SelfA convenience builder-like function for a progress bar with a given tab width
fn with_prefix<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: Self, prefix: impl Into<Cow<'static, str>>) -> SelfA convenience builder-like function for a progress bar with a given prefix
For the prefix to be visible, the
{prefix}placeholder must be present in the template (seeProgressStyle).fn with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: Self, message: impl Into<Cow<'static, str>>) -> SelfA convenience builder-like function for a progress bar with a given message
For the message to be visible, the
{msg}placeholder must be present in the template (seeProgressStyle).fn with_position(self: Self, pos: u64) -> SelfA convenience builder-like function for a progress bar with a given position
fn with_elapsed(self: Self, elapsed: Duration) -> SelfA convenience builder-like function for a progress bar with a given elapsed time
fn with_finish(self: Self, finish: ProgressFinish) -> SelfSets the finish behavior for the progress bar
This behavior is invoked when
ProgressBarorProgressBarItercompletes andProgressBar::is_finished()is false. If you don't want the progress bar to be automatically finished then callwith_finish(Abandon).fn new_spinner() -> SelfCreates a new spinner
This spinner by default draws directly to stderr. This adds the default spinner style to it.
fn set_style(self: &Self, style: ProgressStyle)Overrides the stored style
This does not redraw the bar. Call [
ProgressBar::tick()] to force it.fn set_tab_width(self: &Self, tab_width: usize)Sets the tab width (default: 8). All tabs will be expanded to this many spaces.
fn enable_steady_tick(self: &Self, interval: Duration)Spawns a background thread to tick the progress bar
When this is enabled a background thread will regularly tick the progress bar in the given interval. This is useful to advance progress bars that are very slow by themselves.
When steady ticks are enabled, calling [
ProgressBar::tick()] on a progress bar does not have any effect.fn disable_steady_tick(self: &Self)Undoes [
ProgressBar::enable_steady_tick()]fn tick(self: &Self)Manually ticks the spinner or progress bar
This automatically happens on any other change to a progress bar.
fn inc(self: &Self, delta: u64)Advances the position of the progress bar by
deltafn dec(self: &Self, delta: u64)Decrease the position of the progress bar by
deltaA quick convenience check if the progress bar is hidden
fn is_finished(self: &Self) -> boolIndicates that the progress bar finished
fn println<I: AsRef<str>>(self: &Self, msg: I)Print a log line above the progress bar
If the progress bar is hidden (e.g. when standard output is not a terminal),
println()will not do anything. If you want to write to the standard output in such cases as well, useProgressBar::suspend()instead.If the progress bar was added to a
MultiProgress, the log line will be printed above all other progress bars.fn update<impl FnOnce(&mut ProgressState): FnOnce(&mut ProgressState)>(self: &Self, f: impl FnOnce(&mut ProgressState))Update the
ProgressBar's innerProgressStatefn set_position(self: &Self, pos: u64)Sets the position of the progress bar
fn unset_length(self: &Self)Sets the length of the progress bar to
Nonefn set_length(self: &Self, len: u64)Sets the length of the progress bar
fn inc_length(self: &Self, delta: u64)Increase the length of the progress bar
fn dec_length(self: &Self, delta: u64)Decrease the length of the progress bar
fn set_prefix<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, prefix: impl Into<Cow<'static, str>>)Sets the current prefix of the progress bar
For the prefix to be visible, the
{prefix}placeholder must be present in the template (seeProgressStyle).fn set_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)Sets the current message of the progress bar
For the message to be visible, the
{msg}placeholder must be present in the template (seeProgressStyle).fn set_elapsed(self: &Self, elapsed: Duration)Sets the elapsed time for the progress bar
fn downgrade(self: &Self) -> WeakProgressBarCreates a new weak reference to this
ProgressBarfn reset_eta(self: &Self)Resets the ETA calculation
This can be useful if the progress bars made a large jump or was paused for a prolonged time.
fn reset_elapsed(self: &Self)Resets elapsed time and the ETA calculation
fn reset(self: &Self)Resets all of the progress bar state
fn finish(self: &Self)Finishes the progress bar and leaves the current message
fn finish_with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)Finishes the progress bar and sets a message
For the message to be visible, the
{msg}placeholder must be present in the template (seeProgressStyle).fn finish_and_clear(self: &Self)Finishes the progress bar and completely clears it
fn abandon(self: &Self)Finishes the progress bar and leaves the current message and progress
fn abandon_with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)Finishes the progress bar and sets a message, and leaves the current progress
For the message to be visible, the
{msg}placeholder must be present in the template (seeProgressStyle).fn finish_using_style(self: &Self)Finishes the progress bar using the behavior stored in the
ProgressStyleSee [
ProgressBar::with_finish()].fn set_draw_target(self: &Self, target: ProgressDrawTarget)Sets a different draw target for the progress bar
This can be used to draw the progress bar to stderr (this is the default):
# use ; let pb = new; pb.set_draw_target;Note: Calling this method on a
ProgressBarlinked with aMultiProgress(after runningMultiProgress::add()) will unlink this progress bar. If you don't want this behavior, callMultiProgress::set_draw_target()instead.Use [
ProgressBar::with_draw_target()] to set the draw target during creation.fn force_draw(self: &Self)Force a redraw of the progress bar to be in sync with its state
For performance reasons the progress bar is not redrawn on each state update. This is normally not an issue, since new updates will eventually trigger rendering.
For slow running tasks it is recommended to rely on [
ProgressBar::enable_steady_tick()] to ensure continued rendering of the progress bar.fn suspend<F: FnOnce() -> R, R>(self: &Self, f: F) -> RHide the progress bar temporarily, execute
f, then redraw the progress barUseful for external code that writes to the standard output.
If the progress bar was added to a
MultiProgress, it will suspend the entireMultiProgress.Note: The internal lock is held while
fis executed. Other threads trying to print anything on the progress bar will be blocked untilffinishes. Therefore, it is recommended to avoid long-running operations inf.# use ProgressBar; let mut pb = new; pb.suspendfn wrap_iter<It: Iterator>(self: &Self, it: It) -> ProgressBarIter<It>Wraps an
Iteratorwith the progress bar# use ProgressBar; let v = vec!; let pb = new; for item in pb.wrap_iterfn wrap_read<R: io::Read>(self: &Self, read: R) -> ProgressBarIter<R>Wraps an
io::Readwith the progress bar# use File; # use io; # use ProgressBar; #fn wrap_write<W: io::Write>(self: &Self, write: W) -> ProgressBarIter<W>Wraps an
io::Writewith the progress bar# use File; # use io; # use ProgressBar; #fn position(self: &Self) -> u64Returns the current position
fn length(self: &Self) -> Option<u64>Returns the current length
fn eta(self: &Self) -> DurationReturns the current ETA
fn per_sec(self: &Self) -> f64Returns the current rate of progress
fn duration(self: &Self) -> DurationReturns the current expected duration
fn elapsed(self: &Self) -> DurationReturns the current elapsed time
fn message(self: &Self) -> StringCurrent message
fn prefix(self: &Self) -> StringCurrent prefix
impl Clone for ProgressBar
fn clone(self: &Self) -> ProgressBar
impl Debug for ProgressBar
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for ProgressBar
impl RefUnwindSafe for ProgressBar
impl Send for ProgressBar
impl Sync for ProgressBar
impl Unpin for ProgressBar
impl UnsafeUnpin for ProgressBar
impl UnwindSafe for ProgressBar
impl<T> Any for ProgressBar
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ProgressBar
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ProgressBar
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ProgressBar
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for ProgressBar
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for ProgressBar
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for ProgressBar
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ProgressBar
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ProgressBar
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>