Struct progress_string::Bar
source · [−]Expand description
Represents a progress bar which can be used to get your progress string.
Fields
current_partial: usize
total: usize
Implementations
sourceimpl Bar
impl Bar
sourcepub fn update(&mut self, to_add: usize)
pub fn update(&mut self, to_add: usize)
Update the current_partial
value by adding the to_add
parameter.
Examples
use progress_string::Bar;
let mut bar = Bar::default();
bar.update(10);
assert_eq!(bar.current_partial, 10);
sourcepub fn replace(&mut self, new_progress: usize)
pub fn replace(&mut self, new_progress: usize)
Update the current partial by replacing the current value.
Examples
use progress_string::Bar;
let mut bar = Bar::default();
bar.replace(10);
assert_eq!(bar.current_partial, 10);
sourcepub fn get_width(&self) -> usize
pub fn get_width(&self) -> usize
Get the current width of characters in the bar.
This includes the brackets, spaces and percent if set.
Examples
use progress_string::{Bar, BarBuilder};
let bar = Bar::default();
assert_eq!(bar.get_width(), 52);
let mut with_percent = BarBuilder::new().include_percent().build();
assert_eq!(with_percent.get_width(), 58);
with_percent.update(10);
assert_eq!(with_percent.get_width(), 59);
with_percent.replace(100);
assert_eq!(with_percent.get_width(), 60);
sourcepub fn get_last_width(&self) -> usize
pub fn get_last_width(&self) -> usize
Similar to get_width
but gets the value before the last update
or replace
call.
This is useful for when you are trying to clear the terminal.
Trait Implementations
sourceimpl Display for Bar
impl Display for Bar
sourcefn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Get the string representation of the progress bar.
This string will include brackets ([]) around the empty/full characters. The width is
determined by the width property. If bar.include_percent == true
, the resulting string
will include a space and the percent with 2 decimal places followed by %.
Examples
use progress_string::BarBuilder;
let mut with_percent = BarBuilder::new().include_percent().build();
with_percent.update(50);
println!("{}", with_percent.to_string());
// prints [█████████████████████████ ] 50.00%
let mut no_percent = BarBuilder::new().build();
no_percent.update(50);
// prints [█████████████████████████ ]
Auto Trait Implementations
impl RefUnwindSafe for Bar
impl Send for Bar
impl Sync for Bar
impl Unpin for Bar
impl UnwindSafe for Bar
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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