fluvio_controlplane_metadata/spu/
status.rs1#![allow(clippy::assign_op_pattern)]
2
3use std::fmt;
9
10use fluvio_protocol::{Encoder, Decoder};
11
12#[derive(Decoder, Encoder, Default, Debug, Clone, Eq, PartialEq)]
13#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct SpuStatus {
15 pub resolution: SpuStatusResolution,
16}
17
18impl fmt::Display for SpuStatus {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 write!(f, "{:#?}", self.resolution)
21 }
22}
23
24impl SpuStatus {
25 pub fn offline() -> Self {
27 Self {
28 resolution: SpuStatusResolution::Offline,
29 }
30 }
31 pub fn resolution_label(&self) -> &'static str {
33 match self.resolution {
34 SpuStatusResolution::Online => "online",
35 SpuStatusResolution::Offline => "offline",
36 SpuStatusResolution::Init => "Init",
37 }
38 }
39
40 pub fn is_online(&self) -> bool {
42 self.resolution == SpuStatusResolution::Online
43 }
44
45 pub fn is_offline(&self) -> bool {
46 self.resolution == SpuStatusResolution::Offline
47 }
48
49 pub fn is_init(&self) -> bool {
50 self.resolution == SpuStatusResolution::Init
51 }
52
53 pub fn set_online(&mut self) {
55 self.resolution = SpuStatusResolution::Online;
56 }
57
58 pub fn set_offline(&mut self) {
60 self.resolution = SpuStatusResolution::Offline;
61 }
62}
63
64#[derive(Decoder, Encoder, Debug, Clone, Eq, PartialEq)]
65#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))]
66pub enum SpuStatusResolution {
67 #[fluvio(tag = 0)]
68 Online,
69 #[fluvio(tag = 1)]
70 Offline,
71 #[fluvio(tag = 2)]
72 Init,
73}
74
75impl Default for SpuStatusResolution {
76 fn default() -> Self {
77 Self::Init
78 }
79}