mdns_proto/wire/
resource_class.rs1use derive_more::{Display, IsVariant, TryUnwrap, Unwrap};
4
5pub const CACHE_FLUSH_BIT: u16 = 0x8000;
9
10pub const UNICAST_RESPONSE_BIT: u16 = 0x8000;
13
14#[derive(
17 Debug, Display, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, IsVariant, Unwrap, TryUnwrap,
18)]
19#[display("{}", self.as_str())]
20#[non_exhaustive]
21pub enum ResourceClass {
22 In,
24 Any,
26 Unknown(u16),
28}
29
30impl ResourceClass {
31 pub const fn as_str(&self) -> &'static str {
33 match self {
34 Self::In => "in",
35 Self::Any => "any",
36 Self::Unknown(_) => "unknown",
37 }
38 }
39
40 #[inline(always)]
42 pub const fn to_u16(self) -> u16 {
43 match self {
44 Self::In => 1,
45 Self::Any => 255,
46 Self::Unknown(v) => v,
47 }
48 }
49
50 #[inline(always)]
54 pub const fn from_u16(v: u16) -> Self {
55 Self::from_u16_raw(v & !CACHE_FLUSH_BIT)
56 }
57
58 #[inline(always)]
60 pub const fn from_u16_raw(v: u16) -> Self {
61 match v {
62 1 => Self::In,
63 255 => Self::Any,
64 other => Self::Unknown(other),
65 }
66 }
67}
68
69#[cfg(test)]
70#[allow(clippy::unwrap_used)]
71mod tests;