readstat/progress.rs
1//! Progress reporting trait for parsing feedback.
2//!
3//! The [`ProgressCallback`] trait allows callers to receive progress updates
4//! during data parsing without coupling the library to any specific progress
5//! bar implementation. The CLI crate provides an `indicatif`-based implementation.
6
7/// Trait for receiving progress updates during data parsing.
8///
9/// Implement this trait to display a progress bar, log progress, or perform
10/// any other action when the parser makes forward progress.
11///
12/// # Example
13///
14/// ```
15/// use std::sync::Arc;
16/// use readstat::ProgressCallback;
17///
18/// struct LogProgress;
19///
20/// impl ProgressCallback for LogProgress {
21/// fn inc(&self, n: u64) {
22/// println!("Processed {n} more rows");
23/// }
24/// fn parsing_started(&self, path: &str) {
25/// println!("Parsing file: {path}");
26/// }
27/// }
28/// ```
29pub trait ProgressCallback: Send + Sync {
30 /// Called to report that `n` additional rows have been processed.
31 fn inc(&self, n: u64);
32
33 /// Called when parsing begins for the file at `path`.
34 fn parsing_started(&self, path: &str);
35}