parallel_disk_usage/reporter/
progress_report.rs

1use crate::{size, status_board::GLOBAL_STATUS_BOARD};
2use std::fmt::Write;
3
4/// Scan progress.
5#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub struct ProgressReport<Size: size::Size> {
7    /// Number of scanned items.
8    pub items: u64,
9    /// Total size of scanned items.
10    pub total: Size,
11    /// Number of occurred errors.
12    pub errors: u64,
13}
14
15impl<Size: size::Size + Into<u64>> ProgressReport<Size> {
16    /// Print progress to stderr.
17    pub const TEXT: fn(Self) = |report| {
18        let ProgressReport {
19            items,
20            total,
21            errors,
22        } = report;
23        let mut text = String::new();
24        write!(
25            text,
26            "\r(scanned {items}, total {total}",
27            items = items,
28            total = total.into(),
29        )
30        .unwrap();
31        if errors != 0 {
32            write!(text, ", erred {errors}").unwrap();
33        }
34        write!(text, ")").unwrap();
35        GLOBAL_STATUS_BOARD.temporary_message(&text);
36    };
37}