const RT_SCOPE_UNIVERSE: u8 = 0;
const RT_SCOPE_SITE: u8 = 200;
const RT_SCOPE_LINK: u8 = 253;
const RT_SCOPE_HOST: u8 = 254;
const RT_SCOPE_NOWHERE: u8 = 255;
#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
#[non_exhaustive]
#[repr(u8)]
pub enum AddressScope {
#[default]
Universe,
Site,
Link,
Host,
Nowhere,
Other(u8),
}
impl From<u8> for AddressScope {
fn from(d: u8) -> Self {
match d {
RT_SCOPE_UNIVERSE => Self::Universe,
RT_SCOPE_SITE => Self::Site,
RT_SCOPE_LINK => Self::Link,
RT_SCOPE_HOST => Self::Host,
RT_SCOPE_NOWHERE => Self::Nowhere,
_ => Self::Other(d),
}
}
}
impl From<AddressScope> for u8 {
fn from(v: AddressScope) -> u8 {
match v {
AddressScope::Universe => RT_SCOPE_UNIVERSE,
AddressScope::Site => RT_SCOPE_SITE,
AddressScope::Link => RT_SCOPE_LINK,
AddressScope::Host => RT_SCOPE_HOST,
AddressScope::Nowhere => RT_SCOPE_NOWHERE,
AddressScope::Other(d) => d,
}
}
}
impl std::fmt::Display for AddressScope {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Universe => f.write_str("universe"),
Self::Site => f.write_str("site"),
Self::Link => f.write_str("link"),
Self::Host => f.write_str("host"),
Self::Nowhere => f.write_str("nowhere"),
Self::Other(d) => write!(f, "{d}"),
}
}
}