fluvio_controlplane_metadata/tableformat/
status.rs

1#![allow(clippy::assign_op_pattern)]
2
3use std::fmt;
4
5use fluvio_protocol::{Encoder, Decoder};
6
7#[derive(Encoder, Decoder, Default, Debug, Clone, Eq, PartialEq)]
8#[cfg_attr(
9    feature = "use_serde",
10    derive(serde::Serialize, serde::Deserialize),
11    serde(rename_all = "camelCase")
12)]
13pub struct TableFormatStatus {
14    /// Status resolution
15    pub resolution: TableFormatStatusResolution,
16
17    /// Reason for Status resolution (if applies)
18    pub reason: Option<String>,
19}
20
21impl fmt::Display for TableFormatStatus {
22    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23        write!(f, "{:#?}", self.resolution)
24    }
25}
26
27impl TableFormatStatus {
28    pub fn invalid(reason: String) -> Self {
29        Self {
30            resolution: TableFormatStatusResolution::Invalid,
31            reason: Some(reason),
32        }
33    }
34
35    pub fn reserved() -> Self {
36        Self {
37            resolution: TableFormatStatusResolution::Running,
38            ..Default::default()
39        }
40    }
41
42    pub fn is_already_valid(&self) -> bool {
43        self.resolution == TableFormatStatusResolution::Running
44    }
45}
46
47#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))]
48#[derive(Encoder, Decoder, Debug, Clone, Eq, PartialEq)]
49pub enum TableFormatStatusResolution {
50    #[fluvio(tag = 0)]
51    Init,
52    #[fluvio(tag = 1)]
53    Invalid,
54    #[fluvio(tag = 2)]
55    Running,
56    #[fluvio(tag = 3)]
57    Pending,
58    #[fluvio(tag = 4)]
59    Failed,
60}
61
62impl Default for TableFormatStatusResolution {
63    fn default() -> Self {
64        Self::Init
65    }
66}
67
68impl fmt::Display for TableFormatStatusResolution {
69    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70        match self {
71            Self::Init => write!(f, "Init"),
72            Self::Invalid => write!(f, "Invalid"),
73            Self::Running => write!(f, "Running"),
74            Self::Pending => write!(f, "Pending"),
75            Self::Failed => write!(f, "Failed"),
76        }
77    }
78}