pub trait ProgressReporter: Send + Sync {
// Required methods
fn set_length(&self, len: u64);
fn set_position(&self, pos: u64);
fn set_message(&self, msg: String);
fn finish(&self);
fn finish_with_message(&self, msg: String);
}Expand description
A trait for reporting progress, abstracting over specific implementations like indicatif.
§Examples
use dircat::progress::ProgressReporter;
use std::sync::Mutex;
// A mock reporter that just stores the last message.
struct MockProgress {
last_message: Mutex<String>,
}
impl ProgressReporter for MockProgress {
fn set_length(&self, len: u64) {}
fn set_position(&self, pos: u64) {}
fn set_message(&self, msg: String) {
*self.last_message.lock().unwrap() = msg;
}
fn finish(&self) {}
fn finish_with_message(&self, msg: String) {
*self.last_message.lock().unwrap() = msg;
}
}
let reporter = MockProgress { last_message: Mutex::new("".to_string()) };
reporter.set_message("Working...".to_string());
assert_eq!(*reporter.last_message.lock().unwrap(), "Working...");
reporter.finish_with_message("Done.".to_string());
assert_eq!(*reporter.last_message.lock().unwrap(), "Done.");Required Methods§
Sourcefn set_length(&self, len: u64)
fn set_length(&self, len: u64)
Sets the total number of items to process.
Sourcefn set_position(&self, pos: u64)
fn set_position(&self, pos: u64)
Sets the current position in the process.
Sourcefn set_message(&self, msg: String)
fn set_message(&self, msg: String)
Sets a descriptive message for the current operation (e.g., “Cloning…”).
Sourcefn finish_with_message(&self, msg: String)
fn finish_with_message(&self, msg: String)
Finishes the progress reporting with a final message and hides the progress bar.
Implementors§
impl ProgressReporter for IndicatifProgress
Available on crate feature
progress only.