#[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)]
#[display(doc_comments)]
#[repr(u8)]
pub enum ServerError {
GeneralFailure = 1,
NotAllowed = 2,
NetworkUnreachable = 3,
HostUnreachable = 4,
ConnectionRefused = 5,
TtlExpired = 6,
CommandNotSupported = 7,
AddressNotSupported = 8,
Unknown = 0xFF,
}
impl From<u8> for ServerError {
fn from(value: u8) -> Self {
const ALL: [ServerError; 9] = [
ServerError::GeneralFailure,
ServerError::NotAllowed,
ServerError::NetworkUnreachable,
ServerError::HostUnreachable,
ServerError::ConnectionRefused,
ServerError::TtlExpired,
ServerError::CommandNotSupported,
ServerError::AddressNotSupported,
ServerError::Unknown,
];
for ty in ALL {
if ty as u8 == value {
return ty;
}
}
unreachable!()
}
}