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