fluvio_controlplane_metadata/spg/
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 SpuGroupStatus {
14    /// Status resolution
15    pub resolution: SpuGroupStatusResolution,
16
17    /// Reason for Status resolution (if applies)
18    pub reason: Option<String>,
19}
20
21impl fmt::Display for SpuGroupStatus {
22    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23        write!(f, "{:#?}", self.resolution)
24    }
25}
26
27impl SpuGroupStatus {
28    pub fn invalid(reason: String) -> Self {
29        Self {
30            resolution: SpuGroupStatusResolution::Invalid,
31            reason: Some(reason),
32        }
33    }
34
35    pub fn reserved() -> Self {
36        Self {
37            resolution: SpuGroupStatusResolution::Reserved,
38            ..Default::default()
39        }
40    }
41
42    pub fn is_already_valid(&self) -> bool {
43        self.resolution == SpuGroupStatusResolution::Reserved
44    }
45}
46
47#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))]
48#[derive(Encoder, Decoder, Debug, Clone, Eq, PartialEq)]
49pub enum SpuGroupStatusResolution {
50    #[fluvio(tag = 0)]
51    Init,
52    #[fluvio(tag = 1)]
53    Invalid,
54    #[fluvio(tag = 2)]
55    Reserved,
56}
57
58// -----------------------------------
59// Implementation - FlvSpuGroupResolution
60// -----------------------------------
61impl Default for SpuGroupStatusResolution {
62    fn default() -> Self {
63        Self::Init
64    }
65}
66
67impl fmt::Display for SpuGroupStatusResolution {
68    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69        match self {
70            Self::Init => write!(f, "Init"),
71            Self::Invalid => write!(f, "Invalid"),
72            Self::Reserved => write!(f, "Reserved"),
73        }
74    }
75}