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::{
11 Event,
12 ReporterError,
13};
14
15/// Consumes complete immutable progress events.
16pub trait Reporter: Send + Sync {
17 /// Returns whether a new operation should emit events.
18 ///
19 /// [`crate::ProgressBuilder::start`] samples this once per operation.
20 fn is_enabled(&self) -> bool {
21 true
22 }
23
24 /// Delivers one complete event.
25 ///
26 /// Returns [`ReporterError`] without discarding the sink's error source.
27 fn report(&self, event: &Event) -> Result<(), ReporterError>;
28}
29
30impl<F> Reporter for F
31where
32 F: Fn(&Event) -> Result<(), ReporterError> + Send + Sync,
33{
34 /// Invokes this closure for one complete event.
35 fn report(&self, event: &Event) -> Result<(), ReporterError> {
36 self(event)
37 }
38}