pub struct Bar {
    pub current_partial: usize,
    pub total: usize,
    /* private fields */
}
Expand description

Represents a progress bar which can be used to get your progress string.

Fields

current_partial: usizetotal: usize

Implementations

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);

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);

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);

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

Bar constructor with default values.

Bar {
    current_partial: 0,
    total: 100,
    width: 50,
    full_char:  '█',
    empty_char: ' ',
    leading_char: '█',
    include_percent: false,
    include_numbers: false,
    previous_text_width: 0
}

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

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.