summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
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());
+ }
}