#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ConnectionState {
Connected,
#[default]
Disconnected,
Reconnecting,
}
impl ConnectionState {
#[must_use]
pub fn can_send(&self) -> bool {
matches!(self, Self::Connected)
}
#[must_use]
pub fn can_receive(&self) -> bool {
matches!(self, Self::Connected)
}
#[must_use]
pub fn is_active(&self) -> bool {
matches!(self, Self::Connected)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_can_send() {
assert!(ConnectionState::Connected.can_send());
assert!(!ConnectionState::Disconnected.can_send());
assert!(!ConnectionState::Reconnecting.can_send());
}
#[test]
fn test_can_receive() {
assert!(ConnectionState::Connected.can_receive());
assert!(!ConnectionState::Disconnected.can_receive());
assert!(!ConnectionState::Reconnecting.can_receive());
}
}