pub struct Bar { /* private fields */ }
Expand description
Struct that used for presenting progress bar with plain texts.
It looks like:
Doing something [===-------] 70%
§Examples
use std::thread;
extern crate progress;
fn main() {
let bar = progress::Bar::new();
bar.set_job_title("Working...");
for i in 0..11 {
thread::sleep_ms(100);
bar.reach_percent(i * 10);
}
}
Implementations§
Source§impl Bar
impl Bar
Sourcepub fn new() -> Bar
pub fn new() -> Bar
Create a new progress bar.
Examples found in repository?
examples/simple_examples.rs (line 6)
5fn main() {
6 let mut pbar = progress::Bar::new();
7
8 // Add percentage each time
9 {
10 pbar.set_job_title("This...");
11 pbar.add_percent(20);
12 thread::sleep_ms(1000);
13
14 pbar.set_job_title("is...");
15 pbar.add_percent(20);
16 thread::sleep_ms(1000);
17
18 pbar.set_job_title("very...");
19 pbar.add_percent(20);
20 thread::sleep_ms(1000);
21
22 pbar.set_job_title("slow...");
23 pbar.add_percent(20);
24 thread::sleep_ms(1000);
25
26 pbar.set_job_title("job...");
27 pbar.add_percent(20);
28 thread::sleep_ms(1000);
29 }
30 pbar.jobs_done();
31
32 // Or you can directly specify where to go
33 pbar.set_job_title(&"Creating kitties...".to_string());
34 for i in 0..101 {
35 thread::sleep_ms(30);
36 pbar.reach_percent(i);
37 }
38 pbar.jobs_done();
39
40 // It's okay to break the limit!!
41 pbar.set_job_title(&"Creating rainbow kitties...".to_string());
42 for i in 0..501 {
43 thread::sleep_ms(5);
44 pbar.reach_percent(i);
45 }
46 pbar.jobs_done();
47
48 println!("Now the world is filled with rainbow kitties!");
49}
Sourcepub fn jobs_done(&mut self)
pub fn jobs_done(&mut self)
Reset progress percentage to zero and job title to empty string. Also prints “\n”.
Examples found in repository?
examples/simple_examples.rs (line 30)
5fn main() {
6 let mut pbar = progress::Bar::new();
7
8 // Add percentage each time
9 {
10 pbar.set_job_title("This...");
11 pbar.add_percent(20);
12 thread::sleep_ms(1000);
13
14 pbar.set_job_title("is...");
15 pbar.add_percent(20);
16 thread::sleep_ms(1000);
17
18 pbar.set_job_title("very...");
19 pbar.add_percent(20);
20 thread::sleep_ms(1000);
21
22 pbar.set_job_title("slow...");
23 pbar.add_percent(20);
24 thread::sleep_ms(1000);
25
26 pbar.set_job_title("job...");
27 pbar.add_percent(20);
28 thread::sleep_ms(1000);
29 }
30 pbar.jobs_done();
31
32 // Or you can directly specify where to go
33 pbar.set_job_title(&"Creating kitties...".to_string());
34 for i in 0..101 {
35 thread::sleep_ms(30);
36 pbar.reach_percent(i);
37 }
38 pbar.jobs_done();
39
40 // It's okay to break the limit!!
41 pbar.set_job_title(&"Creating rainbow kitties...".to_string());
42 for i in 0..501 {
43 thread::sleep_ms(5);
44 pbar.reach_percent(i);
45 }
46 pbar.jobs_done();
47
48 println!("Now the world is filled with rainbow kitties!");
49}
Sourcepub fn set_job_title(&mut self, new_title: &str)
pub fn set_job_title(&mut self, new_title: &str)
Set text shown in progress bar.
Examples found in repository?
examples/simple_examples.rs (line 10)
5fn main() {
6 let mut pbar = progress::Bar::new();
7
8 // Add percentage each time
9 {
10 pbar.set_job_title("This...");
11 pbar.add_percent(20);
12 thread::sleep_ms(1000);
13
14 pbar.set_job_title("is...");
15 pbar.add_percent(20);
16 thread::sleep_ms(1000);
17
18 pbar.set_job_title("very...");
19 pbar.add_percent(20);
20 thread::sleep_ms(1000);
21
22 pbar.set_job_title("slow...");
23 pbar.add_percent(20);
24 thread::sleep_ms(1000);
25
26 pbar.set_job_title("job...");
27 pbar.add_percent(20);
28 thread::sleep_ms(1000);
29 }
30 pbar.jobs_done();
31
32 // Or you can directly specify where to go
33 pbar.set_job_title(&"Creating kitties...".to_string());
34 for i in 0..101 {
35 thread::sleep_ms(30);
36 pbar.reach_percent(i);
37 }
38 pbar.jobs_done();
39
40 // It's okay to break the limit!!
41 pbar.set_job_title(&"Creating rainbow kitties...".to_string());
42 for i in 0..501 {
43 thread::sleep_ms(5);
44 pbar.reach_percent(i);
45 }
46 pbar.jobs_done();
47
48 println!("Now the world is filled with rainbow kitties!");
49}
Sourcepub fn reach_percent(&mut self, percent: i32)
pub fn reach_percent(&mut self, percent: i32)
Put progress to given percentage.
Examples found in repository?
examples/simple_examples.rs (line 36)
5fn main() {
6 let mut pbar = progress::Bar::new();
7
8 // Add percentage each time
9 {
10 pbar.set_job_title("This...");
11 pbar.add_percent(20);
12 thread::sleep_ms(1000);
13
14 pbar.set_job_title("is...");
15 pbar.add_percent(20);
16 thread::sleep_ms(1000);
17
18 pbar.set_job_title("very...");
19 pbar.add_percent(20);
20 thread::sleep_ms(1000);
21
22 pbar.set_job_title("slow...");
23 pbar.add_percent(20);
24 thread::sleep_ms(1000);
25
26 pbar.set_job_title("job...");
27 pbar.add_percent(20);
28 thread::sleep_ms(1000);
29 }
30 pbar.jobs_done();
31
32 // Or you can directly specify where to go
33 pbar.set_job_title(&"Creating kitties...".to_string());
34 for i in 0..101 {
35 thread::sleep_ms(30);
36 pbar.reach_percent(i);
37 }
38 pbar.jobs_done();
39
40 // It's okay to break the limit!!
41 pbar.set_job_title(&"Creating rainbow kitties...".to_string());
42 for i in 0..501 {
43 thread::sleep_ms(5);
44 pbar.reach_percent(i);
45 }
46 pbar.jobs_done();
47
48 println!("Now the world is filled with rainbow kitties!");
49}
Sourcepub fn add_percent(&mut self, progress: i32)
pub fn add_percent(&mut self, progress: i32)
Increase progress with given percentage.
Examples found in repository?
examples/simple_examples.rs (line 11)
5fn main() {
6 let mut pbar = progress::Bar::new();
7
8 // Add percentage each time
9 {
10 pbar.set_job_title("This...");
11 pbar.add_percent(20);
12 thread::sleep_ms(1000);
13
14 pbar.set_job_title("is...");
15 pbar.add_percent(20);
16 thread::sleep_ms(1000);
17
18 pbar.set_job_title("very...");
19 pbar.add_percent(20);
20 thread::sleep_ms(1000);
21
22 pbar.set_job_title("slow...");
23 pbar.add_percent(20);
24 thread::sleep_ms(1000);
25
26 pbar.set_job_title("job...");
27 pbar.add_percent(20);
28 thread::sleep_ms(1000);
29 }
30 pbar.jobs_done();
31
32 // Or you can directly specify where to go
33 pbar.set_job_title(&"Creating kitties...".to_string());
34 for i in 0..101 {
35 thread::sleep_ms(30);
36 pbar.reach_percent(i);
37 }
38 pbar.jobs_done();
39
40 // It's okay to break the limit!!
41 pbar.set_job_title(&"Creating rainbow kitties...".to_string());
42 for i in 0..501 {
43 thread::sleep_ms(5);
44 pbar.reach_percent(i);
45 }
46 pbar.jobs_done();
47
48 println!("Now the world is filled with rainbow kitties!");
49}
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