[][src]Trait progressing::Bar

pub trait Bar: Display {
    type Progress;
    fn bar_len(&self) -> usize;
fn set_bar_len(&mut self, new_bar_len: usize);
fn progress(&self) -> Self::Progress;
fn set<P: Into<Self::Progress>>(&mut self, new_progress: P) -> &mut Self;
fn add<P: Into<Self::Progress>>(&mut self, delta: P) -> &mut Self; fn display(&self) -> String { ... }
fn write_to_stdout<S: Into<String>>(&self, msg: S) -> Result<(), String> { ... }
fn print(&self) -> Result<(), String> { ... }
fn println(&self) -> Result<(), String> { ... }
fn reprint(&self) -> Result<(), String> { ... }
fn reprintln(&self) -> Result<(), String> { ... } }

A trait describing basic functionality for simple text-based progress-bars.

Mini-Examples

use progressing::Bar;

/// Printing value 0.3 clamped to [0, 1]
/// [=====>------------]
fn clamped() -> Result<(), String> {
    println!("Printing value 0.3 clamped to [0, 1]");
    let mut progressbar = progressing::ClampingBar::new();
    progressbar.set_bar_len(20);
    progressbar.set(0.3).reprintln()
}

/// Mapping from [-9, 5] to [0, 1]
/// [================>-] (4 / 5)
fn mapped() -> Result<(), String> {
    println!("Mapping from [-9, 5] to [0, 1]");
    let mut progressbar = progressing::MappingBar::new(-9..=5);
    progressbar.set_bar_len(20);
    progressbar.set(4).reprintln()
}

/// Bernoulli-Bar counting successes (42 / 60) and attempts (# 130)
/// [============>-----] (42 / 60 # 130)
fn bernoulli() -> Result<(), String> {
    println!("Bernoulli-Bar counting successes (42 / 60) and attempts (# 130)");
    let mut progressbar = progressing::BernoulliBar::from_goal(60);
    progressbar.set_bar_len(20);
    progressbar.set((42, 130)).reprintln()
}

fn main() -> Result<(), String> {
    clamped()?;
    println!();
    mapped()?;
    println!();
    bernoulli()?;

    Ok(())
}

Associated Types

Loading content...

Required methods

fn bar_len(&self) -> usize

fn set_bar_len(&mut self, new_bar_len: usize)

Do not shorten the length before reprinting since the line will be overwritten, not cleared.

[========>-] becomes [====>]==>-] instead of [====>] .

fn progress(&self) -> Self::Progress

fn set<P: Into<Self::Progress>>(&mut self, new_progress: P) -> &mut Self

Sets the progress to the given value

fn add<P: Into<Self::Progress>>(&mut self, delta: P) -> &mut Self

Adds the given progress to the current progress

Loading content...

Provided methods

fn display(&self) -> String

Returns the printable progressbar.

fn write_to_stdout<S: Into<String>>(&self, msg: S) -> Result<(), String>

fn print(&self) -> Result<(), String>

Prints a progressbar using given progress. Does not print a newline-character. Use println(...) for printing a newline-character. Use reprint(...) for overwriting the current stdout-line.

Will return error if writing to stdout throws an error.

fn println(&self) -> Result<(), String>

Prints a progressbar using given progress. In additon to print(...), this function prints a new line. Use reprintln(...) for overwriting the current stdout-line.

Will return error if writing to stdout throws an error.

fn reprint(&self) -> Result<(), String>

Prints the current line again with progressbar using given progress. Does not print a newline-character. Use reprintln(...) for reprinting with a newline-character.

Will return error if writing to stdout throws an error.

fn reprintln(&self) -> Result<(), String>

Prints the current line again with progressbar using given progress. In additon to reprint(...), this function prints a new line. Use println(...) for always printing a newline-character.

Will return error if writing to stdout throws an error.

Loading content...

Implementors

impl Bar for BernoulliBar[src]

type Progress = BernoulliProgress

impl Bar for ClampingBar[src]

type Progress = f32

fn set_bar_len(&mut self, new_bar_len: usize)[src]

panics if length is < 3

impl Bar for MappingBar<i32>[src]

type Progress = i32

impl Bar for MappingBar<u32>[src]

type Progress = u32

impl Bar for MappingBar<usize>[src]

type Progress = usize

Loading content...