pub struct ProgressBar { /* private fields */ }

Implementations§

source§

impl ProgressBar

source

pub fn new(max: usize) -> Self

Creates a progress bar with the total number of actions.
You will need to call inc method when an action is completed and the bar progress will be incremented by 1.
Don’t print things with print macro while the bar is running; use the print_info method instead.

Example
use progress_bar::progress_bar::ProgressBar;
use progress_bar::color::{Color, Style};
use std::{thread, time};
 
// if you have 81 pages to load
let mut progress_bar = ProgressBar::new(81);
progress_bar.set_action("Loading", Color::Blue, Style::Bold);

for i in 0..81 {
    // load page
    thread::sleep(time::Duration::from_millis(50));
 
    // log the result
    if i == 14 {
        progress_bar.print_info("Failed", "https://zefzef.zef", Color::Red, Style::Blink);
    } else {
        progress_bar.print_info("Success", "https://example.com", Color::Red, Style::Blink);
    }
     
    // increase the progress by 1
    progress_bar.inc();
}
progress_bar.print_final_info("Loading", "Load complete", Color::LightGreen, Style::Bold);
// Or, to leave the progress bar at 100%:
// progress_bar.finalize();
source

pub fn new_with_eta(max: usize) -> Self

Same as ProgressBar::new but enabled ETA display.

source

pub fn set_width(&mut self, w: usize)

Set the width of the progress bar in caracters in console (default: 50)

source

pub fn set_progression(&mut self, p: usize)

👎Deprecated: Use set_progress instead
source

pub fn set_progress(&mut self, p: usize)

Set the progres

source

pub fn set_max(&mut self, m: usize)

Set the maximum progress

source

pub fn inc(&mut self)

Increment the progress by 1

source

pub fn enable_eta(&mut self)

Resets progress and enables ETA

source

pub fn disable_eta(&mut self)

Disables ETA

source

pub fn set_action(&mut self, a: &str, c: Color, s: Style)

Set the global action displayed before the progress bar.

source

pub fn print_final_info( &mut self, info_name: &str, text: &str, info_color: Color, info_style: Style )

Log something, without display update

source

pub fn print_info( &mut self, info_name: &str, text: &str, info_color: Color, info_style: Style )

Log something

source

pub fn display(&self)

Display the bar

source

pub fn finalize(&mut self)

Mark the end of the progress bar - updates will make a ‘new’ bar

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

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