feat(client): Add useful trait impls to Name
This commit is contained in:
committed by
Sean McArthur
parent
780dead9f2
commit
be5ec45571
@@ -35,6 +35,7 @@ pub trait Resolve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A domain name to resolve into IP addresses.
|
/// A domain name to resolve into IP addresses.
|
||||||
|
#[derive(Clone, Hash, Eq, PartialEq)]
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
host: String,
|
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 {
|
impl FromStr for Name {
|
||||||
type Err = InvalidNameError;
|
type Err = InvalidNameError;
|
||||||
|
|
||||||
@@ -348,7 +355,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_name_from_str() {
|
fn test_name_from_str() {
|
||||||
let name = Name::from_str("test.example.com").expect("Should be a valid domain");
|
const DOMAIN: &str = "test.example.com";
|
||||||
assert_eq!(name.as_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user