#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ConnectionState {
Handshake,
Status,
Login,
Configuration,
Play,
}
impl ConnectionState {
pub fn as_str(&self) -> &'static str {
match self {
Self::Handshake => "handshake",
Self::Status => "status",
Self::Login => "login",
Self::Configuration => "configuration",
Self::Play => "play",
}
}
}
impl std::fmt::Display for ConnectionState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn as_str_all_states() {
assert_eq!(ConnectionState::Handshake.as_str(), "handshake");
assert_eq!(ConnectionState::Status.as_str(), "status");
assert_eq!(ConnectionState::Login.as_str(), "login");
assert_eq!(ConnectionState::Configuration.as_str(), "configuration");
assert_eq!(ConnectionState::Play.as_str(), "play");
}
#[test]
fn display_all_states() {
assert_eq!(ConnectionState::Handshake.to_string(), "handshake");
assert_eq!(ConnectionState::Status.to_string(), "status");
assert_eq!(ConnectionState::Login.to_string(), "login");
assert_eq!(ConnectionState::Configuration.to_string(), "configuration");
assert_eq!(ConnectionState::Play.to_string(), "play");
}
}