canlink_hal/monitor/
state.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub enum ConnectionState {
8 Connected,
12
13 #[default]
17 Disconnected,
18
19 Reconnecting,
23}
24
25impl ConnectionState {
26 #[must_use]
28 pub fn can_send(&self) -> bool {
29 matches!(self, Self::Connected)
30 }
31
32 #[must_use]
34 pub fn can_receive(&self) -> bool {
35 matches!(self, Self::Connected)
36 }
37
38 #[must_use]
40 pub fn is_active(&self) -> bool {
41 matches!(self, Self::Connected)
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_can_send() {
51 assert!(ConnectionState::Connected.can_send());
52 assert!(!ConnectionState::Disconnected.can_send());
53 assert!(!ConnectionState::Reconnecting.can_send());
54 }
55
56 #[test]
57 fn test_can_receive() {
58 assert!(ConnectionState::Connected.can_receive());
59 assert!(!ConnectionState::Disconnected.can_receive());
60 assert!(!ConnectionState::Reconnecting.can_receive());
61 }
62}