qubit_progress/model/progress_phase.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 std::fmt;
11
12/// Lifecycle phase of a progress-producing operation.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum ProgressPhase {
15 /// The operation has started.
16 Started,
17 /// The operation is still running.
18 Running,
19 /// The operation finished successfully.
20 Finished,
21 /// The operation reached a failed terminal state.
22 Failed,
23 /// The operation was canceled before normal completion.
24 Canceled,
25}
26
27impl ProgressPhase {
28 /// Returns the stable lowercase name of this phase.
29 ///
30 /// # Returns
31 ///
32 /// A static string suitable for logs and human-readable reporter output.
33 #[inline]
34 pub const fn as_str(self) -> &'static str {
35 match self {
36 Self::Started => "started",
37 Self::Running => "running",
38 Self::Finished => "finished",
39 Self::Failed => "failed",
40 Self::Canceled => "canceled",
41 }
42 }
43}
44
45impl fmt::Display for ProgressPhase {
46 /// Formats this phase as its stable lowercase name.
47 ///
48 /// # Parameters
49 ///
50 /// * `formatter` - Formatter receiving the phase text.
51 ///
52 /// # Returns
53 ///
54 /// The formatter result.
55 #[inline]
56 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
57 formatter.write_str(self.as_str())
58 }
59}