openthread/ot/types/
external_route_config.rsuse crate::prelude_internal::*;
use core::fmt::{Debug, Formatter};
#[derive(Default, Clone, Copy)]
#[repr(transparent)]
pub struct ExternalRouteConfig(pub otExternalRouteConfig);
impl_ot_castable!(ExternalRouteConfig, otExternalRouteConfig);
impl Debug for ExternalRouteConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.prefix().fmt(f)?;
if self.is_stable() {
write!(f, " STABLE")?;
}
if self.is_next_hop_this_device() {
write!(f, " NEXT_HOP_IS_THIS_DEVICE")?;
}
Ok(())
}
}
impl std::fmt::Display for ExternalRouteConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
std::fmt::Debug::fmt(self, f)
}
}
impl ExternalRouteConfig {
pub fn from_prefix<T: Into<otIp6Prefix>>(prefix: T) -> ExternalRouteConfig {
let mut ret = ExternalRouteConfig(otExternalRouteConfig {
mPrefix: prefix.into(),
mRloc16: 0,
..otExternalRouteConfig::default()
});
ret.set_stable(true);
ret
}
pub fn prefix(&self) -> &Ip6Prefix {
(&self.0.mPrefix).into()
}
pub fn rloc16(&self) -> u16 {
self.0.mRloc16
}
pub fn route_preference(&self) -> RoutePreference {
RoutePreference::from_i32(self.0.mPreference()).expect("Invalid route preference")
}
pub fn set_route_preference(&mut self, pref: RoutePreference) {
self.0.set_mPreference(pref as i32);
}
pub fn is_stable(&self) -> bool {
self.0.mStable()
}
pub fn set_stable(&mut self, x: bool) {
self.0.set_mStable(x)
}
pub fn is_next_hop_this_device(&self) -> bool {
self.0.mNextHopIsThisDevice()
}
}