Struct Bar

Source
pub struct Bar<N> { /* private fields */ }
Expand description

A progress-bar mapping values from [a, b] (e.g. [-9, 5]) to [0, 1].

use progressing::{mapping::Bar as MappingBar, Baring};

/// Mapping from [-9, 5] to [0, 1]
/// [================>-] (4 / 5)
fn main() {
    println!("Mapping from [-9, 5] to [0, 1]");
    let mut progress_bar = MappingBar::with_range(-9, 5);
    progress_bar.set_len(20);
    progress_bar.set(4);
    println!("{}", progress_bar);
}

Implementations§

Source§

impl<N> Bar<N>
where N: Clone,

Source

pub fn with_range(from: N, to: N) -> Bar<N>

Examples found in repository?
examples/simple.rs (line 35)
33fn mapped() {
34    println!("Mapping from [-9, 5] to [0, 1]");
35    let mut progress_bar = MappingBar::with_range(-9, 5);
36    progress_bar.set_len(20);
37    progress_bar.set(4);
38    println!("{}", progress_bar);
39}
40
41/// Mapping from [-9, 5] to [0, 1], but with time-approximation
42/// [================>-] (4 / 5) ~ 2 min
43fn timed_mapped() {
44    println!("Mapping from [-9, 5] to [0, 1], but with time-approximation");
45    let mut progress_bar = MappingBar::with_range(-9, 5).timed();
46    progress_bar.set_len(20);
47    progress_bar.set(4);
48    println!("{}", progress_bar);
49}
More examples
Hide additional examples
examples/loops.rs (line 63)
50fn mapped() {
51    let min_value = -10;
52    let max_value = 100;
53    let min_bar_border = -40;
54    let max_bar_border = 140;
55
56    println!(
57        "The bar is running from {} to {}, but maps [{}, {}] to [0, 1].",
58        min_value, max_value, min_bar_border, max_bar_border
59    );
60    println!("Note that the bar neither starts nor ends at the bar-borders.");
61
62    // create bar
63    let mut progress_bar = MappingBar::with_range(min_bar_border, max_bar_border).timed();
64
65    // do the job and show progress
66    for value in min_value..(max_value + 1) {
67        progress_bar.set(value);
68        if progress_bar.has_progressed_significantly() {
69            progress_bar.remember_significant_progress();
70            println!("{}", progress_bar);
71        }
72
73        // sleep for visual effects ;)
74        thread::sleep(time::Duration::from_millis(SLEEP_MS));
75    }
76    // add new line to finished progress-bar
77    println!("{}", progress_bar);
78}
Source

pub fn with(cfg: Config<N>) -> Bar<N>

Source

pub fn timed(self) -> Bar<Bar<N>>
where Bar<N>: Baring,

Examples found in repository?
examples/simple.rs (line 45)
43fn timed_mapped() {
44    println!("Mapping from [-9, 5] to [0, 1], but with time-approximation");
45    let mut progress_bar = MappingBar::with_range(-9, 5).timed();
46    progress_bar.set_len(20);
47    progress_bar.set(4);
48    println!("{}", progress_bar);
49}
More examples
Hide additional examples
examples/loops.rs (line 63)
50fn mapped() {
51    let min_value = -10;
52    let max_value = 100;
53    let min_bar_border = -40;
54    let max_bar_border = 140;
55
56    println!(
57        "The bar is running from {} to {}, but maps [{}, {}] to [0, 1].",
58        min_value, max_value, min_bar_border, max_bar_border
59    );
60    println!("Note that the bar neither starts nor ends at the bar-borders.");
61
62    // create bar
63    let mut progress_bar = MappingBar::with_range(min_bar_border, max_bar_border).timed();
64
65    // do the job and show progress
66    for value in min_value..(max_value + 1) {
67        progress_bar.set(value);
68        if progress_bar.has_progressed_significantly() {
69            progress_bar.remember_significant_progress();
70            println!("{}", progress_bar);
71        }
72
73        // sleep for visual effects ;)
74        thread::sleep(time::Duration::from_millis(SLEEP_MS));
75    }
76    // add new line to finished progress-bar
77    println!("{}", progress_bar);
78}

Trait Implementations§

Source§

impl Baring for Bar<i32>

Source§

type Progress = i32

Source§

fn len(&self) -> usize

Source§

fn set_len(&mut self, new_bar_len: usize)

Do not shorten the length before reprinting (“\r”) since the line will be overwritten, not cleared. Read more
Source§

fn progress(&self) -> i32

Source§

fn set<P>(&mut self, new_progress: P)
where P: Into<i32>,

Sets the progress to the given value
Source§

fn start(&self) -> i32

Source§

fn end(&self) -> i32

Source§

fn has_progressed_significantly(&self) -> bool

Source§

fn remember_significant_progress(&mut self)

Source§

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

Adds the given progress to the current progress
Source§

impl Baring for Bar<i64>

Source§

type Progress = i64

Source§

fn len(&self) -> usize

Source§

fn set_len(&mut self, new_bar_len: usize)

Do not shorten the length before reprinting (“\r”) since the line will be overwritten, not cleared. Read more
Source§

fn progress(&self) -> i64

Source§

fn set<P>(&mut self, new_progress: P)
where P: Into<i64>,

Sets the progress to the given value
Source§

fn start(&self) -> i64

Source§

fn end(&self) -> i64

Source§

fn has_progressed_significantly(&self) -> bool

Source§

fn remember_significant_progress(&mut self)

Source§

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

Adds the given progress to the current progress
Source§

impl Baring for Bar<usize>

Source§

type Progress = usize

Source§

fn len(&self) -> usize

Source§

fn set_len(&mut self, new_bar_len: usize)

Do not shorten the length before reprinting (“\r”) since the line will be overwritten, not cleared. Read more
Source§

fn progress(&self) -> usize

Source§

fn set<P>(&mut self, new_progress: P)
where P: Into<usize>,

Sets the progress to the given value
Source§

fn start(&self) -> usize

Source§

fn end(&self) -> usize

Source§

fn has_progressed_significantly(&self) -> bool

Source§

fn remember_significant_progress(&mut self)

Source§

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

Adds the given progress to the current progress
Source§

impl<N: Debug> Debug for Bar<N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<N> Display for Bar<N>
where N: Display, Bar<N>: Baring, <Bar<N> as Baring>::Progress: Display,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N> Freeze for Bar<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for Bar<N>
where N: RefUnwindSafe,

§

impl<N> Send for Bar<N>
where N: Send,

§

impl<N> Sync for Bar<N>
where N: Sync,

§

impl<N> Unpin for Bar<N>
where N: Unpin,

§

impl<N> UnwindSafe for Bar<N>
where N: UnwindSafe,

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.