Add the `indicatif` crate to your `Cargo.toml`, import it, and instantiate a `ProgressBar` to track iterations.
How to Add Progress Bars to Rust CLIs (indicatif)
Add the indicatif crate to your Cargo.toml, import it, and instantiate a ProgressBar to track iterations.
[dependencies]
indicatif = "0.17"
use indicatif::ProgressBar;
fn main() {
let pb = ProgressBar::new(100);
for i in 0..100 {
// Your work here
pb.inc(1);
}
pb.finish();
}
Adding progress bars to Rust CLIs with indicatif gives users a visual indicator of task duration. It functions like a website loading bar, filling up as your program completes steps. You use it during long processes like file downloads or data processing to reassure users the program hasn't frozen.