Skip to main content

ProgressCallback

Trait ProgressCallback 

Source
pub trait ProgressCallback: Send + Sync {
    // Required methods
    fn inc(&self, n: u64);
    fn parsing_started(&self, path: &str);
}
Expand description

Trait for receiving progress updates during data parsing.

Implement this trait to display a progress bar, log progress, or perform any other action when the parser makes forward progress.

§Example

use std::sync::Arc;
use readstat::ProgressCallback;

struct LogProgress;

impl ProgressCallback for LogProgress {
    fn inc(&self, n: u64) {
        println!("Processed {n} more rows");
    }
    fn parsing_started(&self, path: &str) {
        println!("Parsing file: {path}");
    }
}

Required Methods§

Source

fn inc(&self, n: u64)

Called to advance progress by n rows. Invoked once per chunk, just after that chunk finishes parsing, so n counts rows already completed (the chunk size) — the displayed position stays in step with work done.

Source

fn parsing_started(&self, path: &str)

Called once when parsing begins for the file at path.

Implementations should be idempotent: the contract is a single “parsing started” notification per parse, but callers may invoke it more than once (e.g. the CLI guards against this internally).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§