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