Struct Bar

Source
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: usize§total: usize

Implementations§

Source§

impl Bar

Source

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

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

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

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§

Source§

impl Default for Bar

Source§

fn default() -> Self

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
}
Source§

impl Display for Bar

Source§

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 Freeze for Bar

§

impl RefUnwindSafe for Bar

§

impl Send for Bar

§

impl Sync for Bar

§

impl Unpin for Bar

§

impl UnwindSafe for Bar

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.