summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2019-11-26 17:43:58 +0000
committerEmīls <emils@mullvad.net>2019-11-27 12:11:46 +0000
commitefc0a899ab27be62f30d8f59f487680c52f25cec (patch)
treed7dcfbf01aee484e6234412ae921c9afa82afff9 /talpid-core/src
parentb2486cd53338f44dd721166c5db02faef4b7b396 (diff)
downloadmullvadvpn-efc0a899ab27be62f30d8f59f487680c52f25cec.tar.xz
mullvadvpn-efc0a899ab27be62f30d8f59f487680c52f25cec.zip
Add fmt::Display to routing::{Route,Node}
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/routing/mod.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/talpid-core/src/routing/mod.rs b/talpid-core/src/routing/mod.rs
index a01ef01723..517e9e7d44 100644
--- a/talpid-core/src/routing/mod.rs
+++ b/talpid-core/src/routing/mod.rs
@@ -3,7 +3,7 @@
// TODO: remove the allow(dead_code) for android once it's up to scratch.
use futures::{sync::oneshot, Future};
use ipnetwork::IpNetwork;
-use std::{collections::HashMap, net::IpAddr};
+use std::{collections::HashMap, fmt, net::IpAddr};
#[cfg(target_os = "macos")]
#[path = "macos.rs"]
@@ -144,6 +144,16 @@ impl Route {
}
}
+impl fmt::Display for Route {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{} via {}", self.prefix, self.node)?;
+ if let Some(metric) = &self.metric {
+ write!(f, " metric {}", *metric)?;
+ }
+ Ok(())
+ }
+}
+
/// A network route that should be applied by the RouteManager.
/// It can either be routed through a specific network node or it can be routed through the current
/// default route.
@@ -224,3 +234,16 @@ impl Node {
self.device.as_ref().map(|s| s.as_ref())
}
}
+
+impl fmt::Display for Node {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ if let Some(ip) = &self.ip {
+ write!(f, "{}", ip)?;
+ }
+ if let Some(device) = &self.device {
+ let extra_space = if self.ip.is_some() { " " } else { "" };
+ write!(f, "{}dev {}", extra_space, device)?;
+ }
+ Ok(())
+ }
+}