summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2016-12-05 18:47:26 +0100
committerLinus Färnstrand <linus@mullvad.net>2016-12-06 23:45:45 +0100
commit91380810eafb1fc8e4ce7cc8c2b6f326cd2bb4f4 (patch)
treeed0eaaea9e821ba6d555426046ce9f7bba11c080 /src
parent053b969c5ed59862b68e573b65d62e1adcf9ddf1 (diff)
downloadmullvadvpn-91380810eafb1fc8e4ce7cc8c2b6f326cd2bb4f4.tar.xz
mullvadvpn-91380810eafb1fc8e4ce7cc8c2b6f326cd2bb4f4.zip
Implement Display for RemoteAddr
Diffstat (limited to 'src')
-rw-r--r--src/net.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/net.rs b/src/net.rs
index 4715bf0b7b..2a7d64b861 100644
--- a/src/net.rs
+++ b/src/net.rs
@@ -62,6 +62,12 @@ fn split_at_colon(s: &str) -> Result<(&str, &str), ()> {
Ok((address, port))
}
+impl fmt::Display for RemoteAddr {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "{}:{}", self.address, self.port)
+ }
+}
+
/// Representation of the errors that can happen when parsing a string into a `RemoteAddr`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AddrParseError {
@@ -153,4 +159,11 @@ mod tests {
let err = RemoteAddr::from_str("example.com:");
assert_eq!(Err(AddrParseError::InvalidPort), err);
}
+
+ #[test]
+ fn remote_addr_to_string() {
+ let formatted_remote = "10.98.150.255:1337";
+ let remote_addr = RemoteAddr::from_str(formatted_remote).unwrap();
+ assert_eq!(formatted_remote, remote_addr.to_string());
+ }
}