Struct progress_bar::pb::ProgressBar
source · [−]pub struct ProgressBar { /* private fields */ }
Implementations
sourceimpl ProgressBar
impl ProgressBar
sourcepub fn new(max: usize) -> Self
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 progression 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);
}
// update the progression 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();
sourcepub fn set_width(&mut self, w: usize)
pub fn set_width(&mut self, w: usize)
Set the width of the progress bar in caracters in console (default: 50)
sourcepub fn set_progression(&mut self, p: usize)
pub fn set_progression(&mut self, p: usize)
Set the progression
sourcepub fn set_action(&mut self, a: &str, c: Color, s: Style)
pub fn set_action(&mut self, a: &str, c: Color, s: Style)
Set the global action displayed before the progress bar.
sourcepub fn print_final_info(
&mut self,
info_name: &str,
text: &str,
info_color: Color,
info_style: Style
)
pub fn print_final_info(
&mut self,
info_name: &str,
text: &str,
info_color: Color,
info_style: Style
)
Log something, without display update
Auto Trait Implementations
impl RefUnwindSafe for ProgressBar
impl Send for ProgressBar
impl Sync for ProgressBar
impl Unpin for ProgressBar
impl UnwindSafe for ProgressBar
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more