Skip to main content

Bar

Struct Bar 

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

A progress-bar counting successes (e.g. 42 out of 60) and respective attempts (e.g. 130).

§Mini-Example

use progressing::{Baring, bernoulli::Bar as BernoulliBar};

/// Bernoulli-Bar counting successes (42 / 60) and attempts (# 130)
/// [============>-----] (42 / 60 # 130)
fn main() {
    println!("Bernoulli-Bar counting successes (42 / 60) and attempts (# 130)");
    let mut progress_bar = BernoulliBar::with_goal(60);
    progress_bar.set_len(20);
    progress_bar.set((42, 130));
    println!("{}", progress_bar);
}

Implementations§

Source§

impl Bar

Source

pub fn with_goal(end: usize) -> Bar

Examples found in repository?
examples/simple.rs (line 55)
53fn bernoulli() {
54    println!("Bernoulli-Bar counting successes (42 / 60) and attempts (# 130)");
55    let mut progress_bar = BernoulliBar::with_goal(60);
56    progress_bar.set_len(20);
57    progress_bar.set((42, 130));
58    progress_bar.add(true);
59    println!("{}", progress_bar);
60
61    let is_successful = true;
62    if is_successful {
63        // Does increase both 42 and 130
64        progress_bar.add(true);
65    } else {
66        // Does increase 130 only
67        progress_bar.add(false);
68    }
69}
70
71/// clamped-example, but with other styles
72fn styles() {
73    println!("Custom styles");
74    let mut progress_bar = ClampingBar::new();
75    progress_bar.set_len(20);
76    progress_bar.set(0.3);
77
78    // different custom styles are possible
79
80    // prints (----->............)
81    progress_bar.set_style("(->.)");
82    println!("{}", progress_bar);
83
84    // prints [#####             ]
85    progress_bar.set_style("[#  ]");
86    println!("{}", progress_bar);
87
88    // prints [#####-------------]
89    progress_bar.set_style("(#--)");
90    println!("{}", progress_bar);
91}
92
93fn remember_progress() {
94    println!("Looped progress");
95
96    // create bar
97    let mut progress_bar = BernoulliBar::with_goal(100).timed();
98    progress_bar.set_len(20);
99    progress_bar.set(13);
100
101    // do the job and show progress
102    for _ in 0..100 {
103        progress_bar.add(true);
104        if progress_bar.has_progressed_significantly() {
105            progress_bar.remember_significant_progress();
106            println!("{}", progress_bar);
107        }
108
109        std::thread::sleep(std::time::Duration::from_millis(100));
110    }
111    println!("{}", progress_bar);
112}
More examples
Hide additional examples
examples/loops.rs (line 93)
80fn bernoulli() {
81    let min_value = -50;
82    let max_value = 120;
83
84    println!(
85        "The bar is running from {} to {} counting successes (if value is even) and attempts ({}).",
86        min_value,
87        max_value,
88        (max_value - min_value) + 1
89    );
90    println!("Note that the bar expects less successes than provided .");
91
92    // create bar
93    let mut progress_bar = BernoulliBar::with_goal(60).timed();
94    // you can reset the length of it
95    progress_bar.set_len(60);
96
97    // do the job and show progress
98    for value in min_value..(max_value + 1) {
99        // job is successful if value is even
100        let is_successful = value % 2 == 0;
101        progress_bar.add(is_successful);
102        if progress_bar.has_progressed_significantly() {
103            progress_bar.remember_significant_progress();
104            println!("{}", progress_bar);
105        }
106
107        // sleep for visual effects ;)
108        thread::sleep(time::Duration::from_millis(SLEEP_MS));
109    }
110    // add new line to finished progress-bar
111    println!("{}", progress_bar);
112}
Source

pub fn timed(self) -> Bar<Bar>

Examples found in repository?
examples/simple.rs (line 97)
93fn remember_progress() {
94    println!("Looped progress");
95
96    // create bar
97    let mut progress_bar = BernoulliBar::with_goal(100).timed();
98    progress_bar.set_len(20);
99    progress_bar.set(13);
100
101    // do the job and show progress
102    for _ in 0..100 {
103        progress_bar.add(true);
104        if progress_bar.has_progressed_significantly() {
105            progress_bar.remember_significant_progress();
106            println!("{}", progress_bar);
107        }
108
109        std::thread::sleep(std::time::Duration::from_millis(100));
110    }
111    println!("{}", progress_bar);
112}
More examples
Hide additional examples
examples/loops.rs (line 93)
80fn bernoulli() {
81    let min_value = -50;
82    let max_value = 120;
83
84    println!(
85        "The bar is running from {} to {} counting successes (if value is even) and attempts ({}).",
86        min_value,
87        max_value,
88        (max_value - min_value) + 1
89    );
90    println!("Note that the bar expects less successes than provided .");
91
92    // create bar
93    let mut progress_bar = BernoulliBar::with_goal(60).timed();
94    // you can reset the length of it
95    progress_bar.set_len(60);
96
97    // do the job and show progress
98    for value in min_value..(max_value + 1) {
99        // job is successful if value is even
100        let is_successful = value % 2 == 0;
101        progress_bar.add(is_successful);
102        if progress_bar.has_progressed_significantly() {
103            progress_bar.remember_significant_progress();
104            println!("{}", progress_bar);
105        }
106
107        // sleep for visual effects ;)
108        thread::sleep(time::Duration::from_millis(SLEEP_MS));
109    }
110    // add new line to finished progress-bar
111    println!("{}", progress_bar);
112}

Trait Implementations§

Source§

impl Baring for Bar

Source§

type Progress = Progress

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) -> Progress

Source§

fn set<P>(&mut self, outcome: P)
where P: Into<Progress>,

Sets the progress to the given value
Source§

fn start(&self) -> Progress

Source§

fn end(&self) -> Progress

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 Debug for Bar

Source§

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

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

impl Display for Bar

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Bar

§

impl RefUnwindSafe for Bar

§

impl Send for Bar

§

impl Sync for Bar

§

impl Unpin for Bar

§

impl UnsafeUnpin for Bar

§

impl UnwindSafe for Bar

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.