qubit_command/output_stream.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9use std::fmt;
10
11/// Output stream whose reader failed.
12///
13/// # Author
14///
15/// Haixing Hu
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum OutputStream {
18 /// Standard output stream.
19 Stdout,
20
21 /// Standard error stream.
22 Stderr,
23}
24
25impl OutputStream {
26 /// Returns a lowercase stream name for diagnostics.
27 ///
28 /// # Returns
29 ///
30 /// `"stdout"` for [`Self::Stdout`] and `"stderr"` for [`Self::Stderr`].
31 #[inline]
32 pub const fn as_str(self) -> &'static str {
33 match self {
34 Self::Stdout => "stdout",
35 Self::Stderr => "stderr",
36 }
37 }
38}
39
40impl fmt::Display for OutputStream {
41 /// Formats this stream name for diagnostics.
42 ///
43 /// # Parameters
44 ///
45 /// * `f` - Formatter receiving the lowercase stream name.
46 ///
47 /// # Returns
48 ///
49 /// [`fmt::Result`] from writing the stream name.
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 f.write_str(self.as_str())
52 }
53}