1#[cfg(test)]
2mod state_test;
3
4use std::fmt;
5
6#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
8pub enum ConnectionState {
9 #[default]
10 Unspecified,
11
12 New,
14
15 Checking,
17
18 Connected,
20
21 Completed,
23
24 Failed,
26
27 Disconnected,
29
30 Closed,
32}
33
34impl fmt::Display for ConnectionState {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 let s = match *self {
37 Self::Unspecified => "Unspecified",
38 Self::New => "New",
39 Self::Checking => "Checking",
40 Self::Connected => "Connected",
41 Self::Completed => "Completed",
42 Self::Failed => "Failed",
43 Self::Disconnected => "Disconnected",
44 Self::Closed => "Closed",
45 };
46 write!(f, "{s}")
47 }
48}
49
50impl From<u8> for ConnectionState {
51 fn from(v: u8) -> Self {
52 match v {
53 1 => Self::New,
54 2 => Self::Checking,
55 3 => Self::Connected,
56 4 => Self::Completed,
57 5 => Self::Failed,
58 6 => Self::Disconnected,
59 7 => Self::Closed,
60 _ => Self::Unspecified,
61 }
62 }
63}
64
65#[derive(Default, PartialEq, Eq, Copy, Clone)]
67pub enum GatheringState {
68 #[default]
69 Unspecified,
70
71 New,
73
74 Gathering,
76
77 Complete,
79}
80
81impl From<u8> for GatheringState {
82 fn from(v: u8) -> Self {
83 match v {
84 1 => Self::New,
85 2 => Self::Gathering,
86 3 => Self::Complete,
87 _ => Self::Unspecified,
88 }
89 }
90}
91
92impl fmt::Display for GatheringState {
93 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94 let s = match *self {
95 Self::New => "new",
96 Self::Gathering => "gathering",
97 Self::Complete => "complete",
98 Self::Unspecified => "unspecified",
99 };
100 write!(f, "{s}")
101 }
102}