Debian Codegraph @

debian/rust-vendor/indicatif/examples/iterator.rs

raw
1 use std::thread;
2 use std::time::Duration;
3
4 use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
5
6 fn main() {
7 // Default styling, attempt to use Iterator::size_hint to count input size
8 for _ in (0..1000).progress() {
9 // ...
10 thread::sleep(Duration::from_millis(5));
11 }
12
13 // Provide explicit number of elements in iterator
14 for _ in (0..1000).progress_count(1000) {
15 // ...
16 thread::sleep(Duration::from_millis(5));
17 }
18
19 // Provide a custom bar style
20 let pb = ProgressBar::new(1000);
21 pb.set_style(
22 ProgressStyle::with_template(
23 "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] ({pos}/{len}, ETA {eta})",
24 )
25 .unwrap(),
26 );
27 for _ in (0..1000).progress_with(pb) {
28 // ...
29 thread::sleep(Duration::from_millis(5));
30 }
31 }