Skip to main content

qubit_progress/reporter/impls/
json_stdout_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::{
11    model::ProgressEvent,
12    reporter::{
13        JsonWriterProgressReporter,
14        ProgressReporter,
15    },
16};
17
18/// Progress reporter that writes JSON metric snapshots to stdout.
19pub struct JsonStdoutProgressReporter {
20    /// JSON writer-backed reporter targeting standard output.
21    inner: JsonWriterProgressReporter<std::io::Stdout>,
22}
23
24impl JsonStdoutProgressReporter {
25    /// Creates a JSON reporter writing to standard output.
26    ///
27    /// # Returns
28    ///
29    /// A JSON stdout progress reporter.
30    #[inline]
31    pub fn new() -> Self {
32        Self {
33            inner: JsonWriterProgressReporter::from_writer(std::io::stdout()),
34        }
35    }
36}
37
38impl Default for JsonStdoutProgressReporter {
39    /// Creates a default JSON stdout progress reporter.
40    ///
41    /// # Returns
42    ///
43    /// A JSON stdout progress reporter.
44    #[inline]
45    fn default() -> Self {
46        Self::new()
47    }
48}
49
50impl ProgressReporter for JsonStdoutProgressReporter {
51    /// Writes one JSON line for every metric snapshot in the event.
52    ///
53    /// # Parameters
54    ///
55    /// * `event` - Progress event to report.
56    #[inline]
57    fn report(&self, event: &ProgressEvent) {
58        self.inner.report(event);
59    }
60}