feat(client): Add useful trait impls to Name

This commit is contained in:
Linus Färnstrand
2019-01-11 13:54:39 +01:00
committed by Sean McArthur
parent 780dead9f2
commit be5ec45571

View File

@@ -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);
}
}