From be5ec45571e0b1c6c2b20fe4ab49ef1b0226a004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 11 Jan 2019 13:54:39 +0100 Subject: [PATCH] feat(client): Add useful trait impls to Name --- src/client/connect/dns.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client/connect/dns.rs b/src/client/connect/dns.rs index ea05c726e6..127cd72836 100644 --- a/src/client/connect/dns.rs +++ b/src/client/connect/dns.rs @@ -35,6 +35,7 @@ pub trait Resolve { } /// A domain name to resolve into IP addresses. +#[derive(Clone, Hash, Eq, PartialEq)] pub struct Name { host: String, } @@ -74,6 +75,12 @@ impl fmt::Debug for Name { } } +impl fmt::Display for Name { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.host, f) + } +} + impl FromStr for Name { type Err = InvalidNameError; @@ -348,7 +355,9 @@ mod tests { #[test] fn test_name_from_str() { - let name = Name::from_str("test.example.com").expect("Should be a valid domain"); - assert_eq!(name.as_str(), "test.example.com"); + const DOMAIN: &str = "test.example.com"; + let name = Name::from_str(DOMAIN).expect("Should be a valid domain"); + assert_eq!(name.as_str(), DOMAIN); + assert_eq!(name.to_string(), DOMAIN); } }