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,
impl<N> Bar<N>where
N: Clone,
Sourcepub fn with_range(from: N, to: N) -> Bar<N>
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
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}
pub fn with(cfg: Config<N>) -> Bar<N>
Sourcepub fn timed(self) -> Bar<Bar<N>>
pub fn timed(self) -> Bar<Bar<N>>
Examples found in repository?
More 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>
impl Baring for Bar<i32>
type Progress = i32
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) -> i32
fn start(&self) -> i32
fn end(&self) -> i32
fn has_progressed_significantly(&self) -> bool
fn remember_significant_progress(&mut self)
Source§impl Baring for Bar<i64>
impl Baring for Bar<i64>
type Progress = i64
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) -> i64
fn start(&self) -> i64
fn end(&self) -> i64
fn has_progressed_significantly(&self) -> bool
fn remember_significant_progress(&mut self)
Source§impl Baring for Bar<usize>
impl Baring for Bar<usize>
type Progress = usize
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) -> usize
fn start(&self) -> usize
fn end(&self) -> usize
fn has_progressed_significantly(&self) -> bool
fn remember_significant_progress(&mut self)
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> 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