Skip to main content

qubit_progress/reporter/
reporter.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Reporter trait for complete immutable events.
9
10use crate::Event;
11use crate::ReporterError;
12
13/// Consumes complete immutable progress events.
14pub trait Reporter: Send + Sync {
15    /// Returns whether a new operation should emit events.
16    ///
17    /// [`crate::ProgressBuilder::start`] samples this once per operation.
18    fn is_enabled(&self) -> bool {
19        true
20    }
21
22    /// Delivers one complete event.
23    ///
24    /// Returns [`ReporterError`] without discarding the sink's error source.
25    fn report(&self, event: &Event) -> Result<(), ReporterError>;
26}
27
28impl<F> Reporter for F
29where
30    F: Fn(&Event) -> Result<(), ReporterError> + Send + Sync,
31{
32    /// Invokes this closure for one complete event.
33    fn report(&self, event: &Event) -> Result<(), ReporterError> {
34        self(event)
35    }
36}