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