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