Struct BarBuilder

Source
pub struct BarBuilder { /* private fields */ }
Expand description

Helper struct for building a progress bar.

§Examples
use progress_string::BarBuilder;

let bar = BarBuilder::new()
                    .total(1000000)
                    .width(20)
                    .empty_char('0')
                    .full_char('X')
                    .include_percent()
                    .build();

the above would look something like this [XXXXXXXXXX0000000000] 50.00%

Implementations§

Source§

impl BarBuilder

Source

pub fn new() -> Self

Create a new BarBuilder.

Source

pub fn total(self, total: usize) -> BarBuilder

Update the total (default 100).

§Examples
use progress_string::BarBuilder;

let thousand = BarBuilder::new().total(1000).build();
// yields [█                                                 ]
Source

pub fn width(self, width: usize) -> BarBuilder

Update the progress section’s width (default 50).

use progress_string::BarBuilder;

let bar = BarBuilder::new().width(10);
// yields [          ]
Source

pub fn empty_char(self, character: char) -> BarBuilder

Update the character you want to use as an empty section of the progress bar (default ’ ’).

§Examples
use progress_string::BarBuilder;

let zero_emp = BarBuilder::new().empty_char('0').build();
// yields
// [██████████00000000000]
Source

pub fn full_char(self, character: char) -> BarBuilder

Update the character you want to use as a full section of the bar (default ‘█’).

§Examples
use progress_string::BarBuilder;

let x_bar = BarBuilder::new().full_char('X').build();
// yields [XXXXXX      ]
let y_bar = BarBuilder::new().full_char('Y').build();
// yields [YYYYYY      ]
Source

pub fn leading_char(self, character: impl Into<Option<char>>) -> BarBuilder

Update the character you want to use to lead the full section of the bar (defaults to the value of full_char if not provided).

§Examples
use progress_string::BarBuilder;

let x_bar = BarBuilder::new()
                .full_char('X')
                .leading_char('}')
                .build();
// yields [XXXXXX}     ]
let y_bar = BarBuilder::new()
                .full_char('Y')
                .leading_char(')')
                .build();
// yields [YYYYYY)     ]
Source

pub fn include_percent(self) -> BarBuilder

Update the bar to include the percent after the bar representation (default false).

§Examples
use progress_string::BarBuilder;

let no_p = BarBuilder::new().include_percent().build();
// yields [██████████          ] 50.00%
let with_p = BarBuilder::new();
// yields [██████████          ]
Source

pub fn include_numbers(self) -> BarBuilder

Update the bar to include the divison after the bar representation.

§Examples
use progress_string::BarBuilder;

let mut no_n = BarBuilder::new().build();
no_n.replace(50);
// yields [██████████          ]
let mut with_n = BarBuilder::new().include_numbers().build();
with_n.replace(50)
// yields [██████████          ] 50/100
Source

pub fn get_bar(self) -> Bar

👎Deprecated

deprecated please use build

Source

pub fn build(self) -> Bar

Complete building your bar and return the updated struct.

§Examples
use progress_string::BarBuilder;

let bar = BarBuilder::new().build();
// yields a default bar instance

Trait Implementations§

Source§

impl Default for BarBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.