Skip to main content

qubit_progress/reporter/
progress_reporter.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use crate::model::ProgressEvent;
11
12/// Receives immutable progress events.
13///
14/// # Examples
15///
16/// ```
17/// use std::sync::Mutex;
18/// use std::time::Duration;
19///
20/// use qubit_progress::{
21///     ProgressCounters,
22///     ProgressEvent,
23///     ProgressPhase,
24///     ProgressReporter,
25/// };
26///
27/// #[derive(Default)]
28/// struct RecordingReporter {
29///     phases: Mutex<Vec<ProgressPhase>>,
30/// }
31///
32/// impl ProgressReporter for RecordingReporter {
33///     fn report(&self, event: &ProgressEvent) {
34///         self.phases.lock().expect("phase list should lock").push(event.phase());
35///     }
36/// }
37///
38/// let reporter = RecordingReporter::default();
39/// reporter.report(&ProgressEvent::started(
40///     ProgressCounters::new(Some(1)),
41///     Duration::ZERO,
42/// ));
43///
44/// assert_eq!(
45///     reporter.phases.lock().expect("phase list should lock").as_slice(),
46///     &[ProgressPhase::Started],
47/// );
48/// ```
49pub trait ProgressReporter: Send + Sync {
50    /// Reports one progress event.
51    ///
52    /// # Parameters
53    ///
54    /// * `event` - Immutable progress event to report.
55    ///
56    /// # Panics
57    ///
58    /// Reporter implementations may panic if their output sink fails. Callers
59    /// decide whether reporter panics are propagated or isolated.
60    fn report(&self, event: &ProgressEvent);
61}