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
impl Bar
Sourcepub fn with_goal(end: usize) -> Bar
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
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}Sourcepub fn timed(self) -> Bar<Bar>
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
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
impl Baring for Bar
type Progress = Progress
fn len(&self) -> usize
Source§fn set_len(&mut self, new_bar_len: usize)
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
fn progress(&self) -> Progress
fn start(&self) -> Progress
fn end(&self) -> Progress
fn has_progressed_significantly(&self) -> bool
fn remember_significant_progress(&mut self)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more