qubit_progress/reporter/impls/human_readable_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 qubit_function::{
11 ArcConsumer,
12 Consumer,
13};
14
15use super::formatted_progress_reporter::FormattedProgressReporter;
16use crate::{
17 model::ProgressEvent,
18 reporter::{
19 ProgressReporter,
20 format::HumanReadableMetricSnapshotFormatter,
21 },
22};
23
24/// Progress reporter that emits human-readable strings to a consumer.
25pub struct HumanReadableProgressReporter<C = ArcConsumer<String>> {
26 /// Formatted reporter using the human-readable formatter.
27 inner: FormattedProgressReporter<HumanReadableMetricSnapshotFormatter, C>,
28}
29
30impl<C> HumanReadableProgressReporter<C> {
31 /// Creates a human-readable progress reporter.
32 ///
33 /// # Parameters
34 ///
35 /// * `consumer` - Consumer receiving formatted human-readable strings.
36 ///
37 /// # Returns
38 ///
39 /// A human-readable progress reporter using the default formatter.
40 #[inline]
41 pub fn new(consumer: C) -> Self {
42 Self {
43 inner: FormattedProgressReporter::new(HumanReadableMetricSnapshotFormatter::new(), consumer),
44 }
45 }
46
47 /// Returns the inner formatted reporter.
48 ///
49 /// # Returns
50 ///
51 /// A shared reference to the inner reporter.
52 #[inline]
53 pub const fn inner(&self) -> &FormattedProgressReporter<HumanReadableMetricSnapshotFormatter, C> {
54 &self.inner
55 }
56}
57
58impl<C> ProgressReporter for HumanReadableProgressReporter<C>
59where
60 C: Consumer<String> + Send + Sync,
61{
62 /// Reports one event through the human-readable formatter.
63 ///
64 /// # Parameters
65 ///
66 /// * `event` - Event to report.
67 #[inline]
68 fn report(&self, event: &ProgressEvent) {
69 self.inner.report(event);
70 }
71}