Struct progress_string::Bar[][src]

pub struct Bar {
    pub current_partial: usize,
    pub total: usize,
    // some fields omitted
}

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

Fields

current_partial: usizetotal: usize

Implementations

impl Bar[src]

pub fn update(&mut self, to_add: usize)[src]

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

pub fn replace(&mut self, new_progress: usize)[src]

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

pub fn get_width(&self) -> usize[src]

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().get_bar();
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);

pub fn get_last_width(&self) -> usize[src]

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

impl Default for Bar[src]

fn default() -> Self[src]

Bar constructor with default values.

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

impl Display for Bar[src]

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

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().get_bar();
with_percent.update(50);
println!("{}", with_percent.to_string());
// prints [█████████████████████████                         ] 50.00%
let mut no_percent = BarBuilder::new().get_bar();
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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.