Trait kdam::BarExt

source ·
pub trait BarExt {
    // Required methods
    fn clear(&mut self) -> Result<()>;
    fn input<T: Into<String>>(&mut self, text: T) -> Result<String>;
    fn refresh(&mut self) -> Result<()>;
    fn render(&mut self) -> String;
    fn reset(&mut self, total: Option<usize>);
    fn update(&mut self, n: usize) -> Result<bool>;
    fn update_to(&mut self, n: usize) -> Result<bool>;
    fn write<T: Into<String>>(&mut self, text: T) -> Result<()>;
    fn write_to<T: Write>(
        &mut self,
        writer: &mut T,
        n: Option<usize>
    ) -> Result<bool>;
}
Expand description

Comman progress bar functionalities shared between different types of progress bars.

Required Methods§

source

fn clear(&mut self) -> Result<()>

Clear current progress bar display.

Returns Err, if writing to handle fails.

source

fn input<T: Into<String>>(&mut self, text: T) -> Result<String>

Take input via progress bar (without overlaping with bar(s)).

Returns Err, if reading from stdin handle fails.

source

fn refresh(&mut self) -> Result<()>

Force refresh current progress bar display.

Returns Err, if writing to handle fails.

source

fn render(&mut self) -> String

Render progress bar text.

source

fn reset(&mut self, total: Option<usize>)

Resets counter to 0 for repeated use.

Consider combining with leave = true.

source

fn update(&mut self, n: usize) -> Result<bool>

Manually update the progress bar, useful for streams such as reading files.

Returns whether an update was triggered or not depending on constraints. Returns Err, if writing to handle fails.

source

fn update_to(&mut self, n: usize) -> Result<bool>

Set counter value instead of incrementing counter through update method.

Returns wheter a update was triggered or not depending on constraints. Returns Err, if writing to handle fails.

source

fn write<T: Into<String>>(&mut self, text: T) -> Result<()>

Print a message via progress bar (without overlaping with bar(s)).

Returns Err, if writing to handle fails.

source

fn write_to<T: Write>( &mut self, writer: &mut T, n: Option<usize> ) -> Result<bool>

Write progress bar rendered text to a writer (useful for writing files).

If n is supplied then this method behaves like update method.

Returns whether a update was triggered or not depending on constraints. Returns Err, if writing to handle fails.

Example

Using write_to as update_to.

use kdam::{tqdm, BarExt};
use std::{fs::File, io::Write};

let mut pb = tqdm!(total = 100, animation = "ascii");
let mut f = File::create("kdam-logs.txt").unwrap();
 
for i in 1..101 {
    pb.counter = i;
    pb.write_to(&mut f, Some(0));
}

Object Safety§

This trait is not object safe.

Implementors§