Skip to content

Commit

Permalink
feat(client): Add useful trait impls to Name
Browse files Browse the repository at this point in the history
  • Loading branch information
faern authored and seanmonstar committed Jan 11, 2019
1 parent 780dead commit be5ec45
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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;

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

0 comments on commit be5ec45

Please sign in to comment.