use derive_more::{Display, IsVariant, TryUnwrap, Unwrap};
pub const CACHE_FLUSH_BIT: u16 = 0x8000;
pub const UNICAST_RESPONSE_BIT: u16 = 0x8000;
#[derive(
Debug, Display, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, IsVariant, Unwrap, TryUnwrap,
)]
#[display("{}", self.as_str())]
#[non_exhaustive]
pub enum ResourceClass {
In,
Any,
Unknown(u16),
}
impl ResourceClass {
pub const fn as_str(&self) -> &'static str {
match self {
Self::In => "in",
Self::Any => "any",
Self::Unknown(_) => "unknown",
}
}
#[inline(always)]
pub const fn to_u16(self) -> u16 {
match self {
Self::In => 1,
Self::Any => 255,
Self::Unknown(v) => v,
}
}
#[inline(always)]
pub const fn from_u16(v: u16) -> Self {
Self::from_u16_raw(v & !CACHE_FLUSH_BIT)
}
#[inline(always)]
pub const fn from_u16_raw(v: u16) -> Self {
match v {
1 => Self::In,
255 => Self::Any,
other => Self::Unknown(other),
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests;