Struct ProgressBar

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

A log-friendly progress bar

Implementations§

Source§

impl ProgressBar

Source

pub fn new(max_progress: usize) -> Self

Create a new progress bar with default style

§Example
let max_progress = 100;
let bar = logbar::ProgressBar::new(max_progress);
Source

pub fn with_style(max_progress: usize, style: Style) -> Self

Create a new progress bar with custom style

§Example

Create a progress bar with a width of 80 characters:

let style = logbar::Style::new().width(80);
let max_progress = 100;
let bar = logbar::ProgressBar::with_style(max_progress, style);
Source

pub fn style(&self) -> &Style

Get the style of the current progress bar

§Example
let max_progress = 100;
let bar = logbar::ProgressBar::new(max_progress);
assert_eq!(bar.style(), &logbar::Style::default())
Source

pub fn inc(&self, i: usize)

Increment the progress

This method increments the internal progress counter, up to the maximum defined during the construction of the progress bar. It then updates the progress display.

§Example
let max_progress = 50;
let bar = logbar::ProgressBar::new(max_progress);
bar.inc(10); // Increment progress to 10 out of 50.
// The progress bar is at 20% now
bar.inc(10); // Increment progress to 20 out of 50.
// The progress bar is at 40% now
bar.inc(100); // Increment progress to 50 out of 50.
// The progress bar is at 100% now
Source

pub fn finish(&self)

Finish the progress bar

This method sets the progress to 100% and moves to the next line after the progress bar

§Example
let max_progress = 50;
let bar = logbar::ProgressBar::new(max_progress);
bar.finish();
// The progress bar is at 100% now

Trait Implementations§

Source§

impl Debug for ProgressBar

Source§

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

Formats the value using the given formatter. 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.