parallel_disk_usage/reporter/
error_only_reporter.rs

1use super::{ErrorReport, Event, ParallelReporter, Reporter};
2use crate::size;
3
4/// Only report errors.
5#[derive(Debug)]
6pub struct ErrorOnlyReporter<ReportError: Fn(ErrorReport)> {
7    /// Report encountered errors.
8    report_error: ReportError,
9}
10
11impl<ReportError: Fn(ErrorReport)> ErrorOnlyReporter<ReportError> {
12    /// Create a new [`ErrorOnlyReporter`].
13    pub fn new(report_error: ReportError) -> Self {
14        ErrorOnlyReporter { report_error }
15    }
16}
17
18impl<Size, ReportError> Reporter<Size> for ErrorOnlyReporter<ReportError>
19where
20    Size: size::Size,
21    ReportError: Fn(ErrorReport),
22{
23    fn report(&self, event: Event<Size>) {
24        let ErrorOnlyReporter { report_error } = self;
25        if let Event::EncounterError(error_report) = event {
26            report_error(error_report);
27        }
28    }
29}
30
31impl<Size, ReportError> ParallelReporter<Size> for ErrorOnlyReporter<ReportError>
32where
33    Size: size::Size,
34    ReportError: Fn(ErrorReport),
35{
36    type DestructionError = (); // TODO: change this to `!` once it is stable.
37    fn destroy(self) -> Result<(), Self::DestructionError> {
38        Ok(())
39    }
40}