pub struct Bar { /* private fields */ }Implementations§
Source§impl Bar
Core implementation of console progress bar.
impl Bar
Core implementation of console progress bar.
§Example
A simple progress bar with a max value.
fn main() {
use rpb::bar::Bar;
let mut bar = Bar::new(100);
for _ in 0..100 {
bar.add(1);
}
}Sourcepub fn new(max: i64) -> Self
pub fn new(max: i64) -> Self
Create a new instance of Bar with a max value.
§Example
use rpb::bar::Bar;
let mut bar = Bar::new(100);Examples found in repository?
More examples
examples/custom.rs (line 7)
6fn main() {
7 let mut bar = Bar::new(100);
8 let mut bar2 = Bar::new(100);
9 let mut bar3 = Bar::new(100);
10 let mut bar4 = Bar::new(100);
11
12 bar.set_theme(Themes::Basic);
13 bar.set_description("bar1");
14
15 bar2.set_theme(Themes::Small);
16 bar2.set_description("bar2");
17
18 bar3.set_theme(Themes::ColoredSmall);
19 bar3.set_description("bar3");
20
21 bar4.set_theme(Themes::ColoredMedium);
22 bar4.set_description("bar4");
23
24 bar2.set_position(1);
25 bar3.set_position(2);
26 bar4.set_position(3);
27
28 for _i in 0..100 {
29 bar.add(1);
30 bar2.add(1);
31 bar3.add(1);
32 bar4.add(1);
33 sleep(time::Duration::from_millis(50))
34 }
35 eprint!("{}", "\n".repeat(4));
36}Sourcepub fn default_bytes(max_bytes: i64, desc: &str) -> Bar
pub fn default_bytes(max_bytes: i64, desc: &str) -> Bar
DefaultBytes provides a progressbar to measure byte throughput with recommended defaults.
§Example:
use rpb::bar::Bar;
let mut bar = Bar::default_bytes(100, "downloading");Sourcepub fn set_theme(&mut self, theme: Themes)
pub fn set_theme(&mut self, theme: Themes)
Instantiate a new theme.
§Example
use rpb::bar::Bar;
use rpb::styles::Themes;
let mut bar = Bar::new(100);
bar.set_theme(Themes::Small);Examples found in repository?
examples/custom.rs (line 12)
6fn main() {
7 let mut bar = Bar::new(100);
8 let mut bar2 = Bar::new(100);
9 let mut bar3 = Bar::new(100);
10 let mut bar4 = Bar::new(100);
11
12 bar.set_theme(Themes::Basic);
13 bar.set_description("bar1");
14
15 bar2.set_theme(Themes::Small);
16 bar2.set_description("bar2");
17
18 bar3.set_theme(Themes::ColoredSmall);
19 bar3.set_description("bar3");
20
21 bar4.set_theme(Themes::ColoredMedium);
22 bar4.set_description("bar4");
23
24 bar2.set_position(1);
25 bar3.set_position(2);
26 bar4.set_position(3);
27
28 for _i in 0..100 {
29 bar.add(1);
30 bar2.add(1);
31 bar3.add(1);
32 bar4.add(1);
33 sleep(time::Duration::from_millis(50))
34 }
35 eprint!("{}", "\n".repeat(4));
36}Sourcepub fn set_position(&mut self, position: u32)
pub fn set_position(&mut self, position: u32)
Sets the position of the progress bar. By default, the progress bar are position 0.
§Example
use rpb::bar::Bar;
let mut bar = Bar::new(100);
bar.set_position(1)Examples found in repository?
examples/custom.rs (line 24)
6fn main() {
7 let mut bar = Bar::new(100);
8 let mut bar2 = Bar::new(100);
9 let mut bar3 = Bar::new(100);
10 let mut bar4 = Bar::new(100);
11
12 bar.set_theme(Themes::Basic);
13 bar.set_description("bar1");
14
15 bar2.set_theme(Themes::Small);
16 bar2.set_description("bar2");
17
18 bar3.set_theme(Themes::ColoredSmall);
19 bar3.set_description("bar3");
20
21 bar4.set_theme(Themes::ColoredMedium);
22 bar4.set_description("bar4");
23
24 bar2.set_position(1);
25 bar3.set_position(2);
26 bar4.set_position(3);
27
28 for _i in 0..100 {
29 bar.add(1);
30 bar2.add(1);
31 bar3.add(1);
32 bar4.add(1);
33 sleep(time::Duration::from_millis(50))
34 }
35 eprint!("{}", "\n".repeat(4));
36}Sourcepub fn set_description(&mut self, desc: &str)
pub fn set_description(&mut self, desc: &str)
Sets description of progress bar.
Examples found in repository?
examples/custom.rs (line 13)
6fn main() {
7 let mut bar = Bar::new(100);
8 let mut bar2 = Bar::new(100);
9 let mut bar3 = Bar::new(100);
10 let mut bar4 = Bar::new(100);
11
12 bar.set_theme(Themes::Basic);
13 bar.set_description("bar1");
14
15 bar2.set_theme(Themes::Small);
16 bar2.set_description("bar2");
17
18 bar3.set_theme(Themes::ColoredSmall);
19 bar3.set_description("bar3");
20
21 bar4.set_theme(Themes::ColoredMedium);
22 bar4.set_description("bar4");
23
24 bar2.set_position(1);
25 bar3.set_position(2);
26 bar4.set_position(3);
27
28 for _i in 0..100 {
29 bar.add(1);
30 bar2.add(1);
31 bar3.add(1);
32 bar4.add(1);
33 sleep(time::Duration::from_millis(50))
34 }
35 eprint!("{}", "\n".repeat(4));
36}Sourcepub fn set_spinner(&mut self, spinner: Spinners)
pub fn set_spinner(&mut self, spinner: Spinners)
Sets spinner of progress bar.
Sourcepub fn set_unit(&mut self, u: Units)
pub fn set_unit(&mut self, u: Units)
Set units, default is Units::Default
§Examples
use rpb::bar::{Bar, Units};
let n_bytes = 100;
let mut bar = Bar::new(n_bytes);
bar.set_unit(Units::Bytes);Sourcepub fn reader<R: Read>(&self, read: R) -> BarIter<R> ⓘ
pub fn reader<R: Read>(&self, read: R) -> BarIter<R> ⓘ
Wraps an io::Read with the progress bar
§Example:
use std::fs::File;
use std::io;
use rpb::bar::Bar;
use rpb::bar::Units;
fn main () -> io::Result<()> {
let src = File::open("src.txt")?;
let mut tgt = File::create("tgt.txt")?;
let mut bar = Bar::new(src.metadata()?.len() as i64);
bar.set_unit(Units::Bytes);
io::copy(&mut bar.reader(src), &mut tgt).unwrap();
Ok(())
}Sourcepub fn writer<R: Write>(&self, write: R) -> BarIter<R> ⓘ
pub fn writer<R: Write>(&self, write: R) -> BarIter<R> ⓘ
Wraps an io::Write with the progress bar
§Example:
use std::fs::File;
use std::io;
use rpb::bar::Bar;
use rpb::bar::Units;
fn main () -> io::Result<()> {
let mut src = File::open("src.txt")?;
let mut tgt = File::create("tgt.txt")?;
let mut bar = Bar::new(src.metadata()?.len() as i64);
bar.set_unit(Units::Bytes);
io::copy(&mut src, &mut bar.writer(tgt)).unwrap();
Ok(())
}Sourcepub fn add(&mut self, num: usize)
pub fn add(&mut self, num: usize)
Manually update the progress bar, advances the position by num.
Examples found in repository?
More examples
examples/custom.rs (line 29)
6fn main() {
7 let mut bar = Bar::new(100);
8 let mut bar2 = Bar::new(100);
9 let mut bar3 = Bar::new(100);
10 let mut bar4 = Bar::new(100);
11
12 bar.set_theme(Themes::Basic);
13 bar.set_description("bar1");
14
15 bar2.set_theme(Themes::Small);
16 bar2.set_description("bar2");
17
18 bar3.set_theme(Themes::ColoredSmall);
19 bar3.set_description("bar3");
20
21 bar4.set_theme(Themes::ColoredMedium);
22 bar4.set_description("bar4");
23
24 bar2.set_position(1);
25 bar3.set_position(2);
26 bar4.set_position(3);
27
28 for _i in 0..100 {
29 bar.add(1);
30 bar2.add(1);
31 bar3.add(1);
32 bar4.add(1);
33 sleep(time::Duration::from_millis(50))
34 }
35 eprint!("{}", "\n".repeat(4));
36}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bar
impl RefUnwindSafe for Bar
impl Send for Bar
impl Sync for Bar
impl Unpin 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