Struct Bar

Source
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

Source

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}
Source

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}
Source

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}
Source

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}
Source

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> 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, 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.