pub struct ProgressBar { /* private fields */ }
Expand description

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§

source§

impl ProgressBar

source

pub fn new(len: u64) -> ProgressBar

Creates a new progress bar with a given length

This progress bar by default draws directly to stderr, and refreshes a maximum of 15 times a second. To change the refresh rate, set the draw target to one with a different refresh rate.

source

pub fn hidden() -> ProgressBar

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.

source

pub fn with_draw_target(len: u64, target: ProgressDrawTarget) -> ProgressBar

Creates a new progress bar with a given length and draw target

source

pub fn with_style(self, style: ProgressStyle) -> ProgressBar

A convenience builder-like function for a progress bar with a given style

source

pub fn with_prefix(self, prefix: impl Into<Cow<'static, str>>) -> ProgressBar

A convenience builder-like function for a progress bar with a given prefix

source

pub fn with_message(self, message: impl Into<Cow<'static, str>>) -> ProgressBar

A convenience builder-like function for a progress bar with a given message

source

pub fn with_position(self, pos: u64) -> ProgressBar

A convenience builder-like function for a progress bar with a given position

source

pub fn new_spinner() -> ProgressBar

Creates a new spinner

This spinner by default draws directly to stderr. This adds the default spinner style to it.

source

pub fn set_style(&self, style: ProgressStyle)

Overrides the stored style

This does not redraw the bar. Call ProgressBar::tick() to force it.

source

pub fn enable_steady_tick(&self, ms: u64)

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 (in milliseconds). 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.

source

pub fn disable_steady_tick(&self)

source

pub fn set_draw_delta(&self, n: u64)

Limit redrawing of progress bar to every n steps

By default, the progress bar will redraw whenever its state advances. This setting is helpful in situations where the overhead of redrawing the progress bar dominates the computation whose progress is being reported.

If n is greater than 0, operations that change the progress bar such as ProgressBar::tick(), ProgressBar::set_message() and ProgressBar::set_length() will no longer cause the progress bar to be redrawn, and will only be shown once the position advances by n steps.

let n = 1_000_000;
let pb = ProgressBar::new(n);
pb.set_draw_delta(n / 100); // redraw every 1% of additional progress

Note that ProgressDrawTarget may impose additional buffering of redraws.

source

pub fn set_draw_rate(&self, n: u64)

Sets the refresh rate of progress bar to n updates per seconds

This is similar to set_draw_delta but automatically adapts to a constant refresh rate regardless of how consistent the progress is.

This parameter takes precedence on set_draw_delta if different from 0.

let n = 1_000_000;
let pb = ProgressBar::new(n);
pb.set_draw_rate(25); // aims at redrawing at most 25 times per seconds.

Note that the ProgressDrawTarget may impose additional buffering of redraws.

source

pub fn tick(&self)

Manually ticks the spinner or progress bar

This automatically happens on any other change to a progress bar.

source

pub fn inc(&self, delta: u64)

Advances the position of the progress bar by delta

source

pub fn is_hidden(&self) -> bool

A quick convenience check if the progress bar is hidden

source

pub fn is_finished(&self) -> bool

Indicates that the progress bar finished

source

pub fn println<I>(&self, msg: I)where I: AsRef<str>,

Print a log line above the progress bar

If the progress bar was added to a MultiProgress, the log line will be printed above all other progress bars.

Note that if the progress bar is hidden (which by default happens if the progress bar is redirected into a file) println() will not do anything either.

source

pub fn set_position(&self, pos: u64)

Sets the position of the progress bar

source

pub fn set_length(&self, len: u64)

Sets the length of the progress bar

source

pub fn inc_length(&self, delta: u64)

Increase the length of the progress bar

source

pub fn set_prefix(&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 (see ProgressStyle).

source

pub fn set_message(&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 (see ProgressStyle).

source

pub fn downgrade(&self) -> WeakProgressBar

Creates a new weak reference to this ProgressBar

source

pub fn reset_eta(&self)

Resets the ETA calculation

This can be useful if the progress bars made a large jump or was paused for a prolonged time.

source

pub fn reset_elapsed(&self)

Resets elapsed time

source

pub fn reset(&self)

Resets all of the progress bar state

source

pub fn finish(&self)

Finishes the progress bar and leaves the current message

source

pub fn finish_at_current_pos(&self)

Finishes the progress bar at current position and leaves the current message

source

pub fn finish_with_message(&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 (see ProgressStyle).

source

pub fn finish_and_clear(&self)

Finishes the progress bar and completely clears it

source

pub fn abandon(&self)

Finishes the progress bar and leaves the current message and progress

source

pub fn abandon_with_message(&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 (see ProgressStyle).

source

pub fn finish_using_style(&self)

Finishes the progress bar using the behavior stored in the ProgressStyle

See ProgressStyle::on_finish().

source

pub fn set_draw_target(&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):

let pb = ProgressBar::new(100);
pb.set_draw_target(ProgressDrawTarget::stderr());

Note: Calling this method on a ProgressBar linked with a MultiProgress (after running MultiProgress::add) will unlink this progress bar. If you don’t want this behavior, call MultiProgress::set_draw_target instead.

source

pub fn wrap_iter<It>(&self, it: It) -> ProgressBarIter<It>where It: Iterator,

Wraps an Iterator with the progress bar

let v = vec![1, 2, 3];
let pb = ProgressBar::new(3);
for item in pb.wrap_iter(v.iter()) {
    // ...
}
source

pub fn wrap_read<R>(&self, read: R) -> ProgressBarIter<R>where R: Read,

Wraps an io::Read with the progress bar

let source = File::open("work.txt")?;
let mut target = File::create("done.txt")?;
let pb = ProgressBar::new(source.metadata()?.len());
io::copy(&mut pb.wrap_read(source), &mut target);
source

pub fn wrap_write<W>(&self, write: W) -> ProgressBarIter<W>where W: Write,

Wraps an io::Write with the progress bar

let mut source = File::open("work.txt")?;
let target = File::create("done.txt")?;
let pb = ProgressBar::new(source.metadata()?.len());
io::copy(&mut source, &mut pb.wrap_write(target));
source

pub fn position(&self) -> u64

Returns the current position

source

pub fn length(&self) -> u64

Returns the current length

source

pub fn eta(&self) -> Duration

Returns the current ETA

source

pub fn per_sec(&self) -> u64

Returns the current rate of progress

source

pub fn duration(&self) -> Duration

Returns the current expected duration

source

pub fn elapsed(&self) -> Duration

Returns the current elapsed time

Trait Implementations§

source§

impl Clone for ProgressBar

source§

fn clone(&self) -> ProgressBar

Returns a copy 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 Debug for ProgressBar

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for Twhere T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

Cast to trait Any
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more