use num_enum::TryFromPrimitive;
const fn errno(code: u16) -> u16 {
((code / 100) << 8) | (code % 100)
}
#[repr(u16)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, TryFromPrimitive)]
pub enum ErrorType {
TryAlternate = errno(300),
BadRequest = errno(400),
Unauthorized = errno(401),
Forbidden = errno(403),
UnknownAttribute = errno(420),
AllocationMismatch = errno(437),
StaleNonce = errno(438),
AddressFamilyNotSupported = errno(440),
WrongCredentials = errno(441),
UnsupportedTransportAddress = errno(442),
PeerAddressFamilyMismatch = errno(443),
AllocationQuotaReached = errno(486),
ServerError = errno(500),
InsufficientCapacity = errno(508),
}
impl From<ErrorType> for &'static str {
#[rustfmt::skip]
fn from(val: ErrorType) -> Self {
match val {
ErrorType::TryAlternate => "Try Alternate",
ErrorType::BadRequest => "Bad Request",
ErrorType::Unauthorized => "Unauthorized",
ErrorType::Forbidden => "Forbidden",
ErrorType::UnknownAttribute => "Unknown Attribute",
ErrorType::AllocationMismatch => "Allocation Mismatch",
ErrorType::StaleNonce => "Stale Nonce",
ErrorType::AddressFamilyNotSupported => "Address Family not Supported",
ErrorType::WrongCredentials => "Wrong Credentials",
ErrorType::UnsupportedTransportAddress => "Unsupported Transport Address",
ErrorType::AllocationQuotaReached => "Allocation Quota Reached",
ErrorType::ServerError => "Server Error",
ErrorType::InsufficientCapacity => "Insufficient Capacity",
ErrorType::PeerAddressFamilyMismatch => "Peer Address Family Mismatch",
}
}
}