pub struct DnsResolver { /* private fields */ }
Expand description
A DNS resolver
Implementations§
Source§impl DnsResolver
impl DnsResolver
Sourcepub fn new(dns: SocketAddr) -> Result<Self, DnsError>
pub fn new(dns: SocketAddr) -> Result<Self, DnsError>
Create a new DNS resolver
§Parameters
dns
: TheSocketAddr
of the DNS server
§Errors
DnsError::FailedToCreate
: The DNS resolver failed to create. This may happen if the socket could not be created or bound to the specified address
Sourcepub fn try_default() -> Result<Self, DnsError>
pub fn try_default() -> Result<Self, DnsError>
Try to create a new DNS resolver with default settings
The default settings are to use Google’s DNS server at 8.8.8.8:53
§Errors
DnsError::FailedToCreate
: The DNS resolver failed to create. This may happen if the socket could not be created or bound to the specified address
Sourcepub fn resolve(&mut self, host: &str) -> Result<in_addr, DnsError>
pub fn resolve(&mut self, host: &str) -> Result<in_addr, DnsError>
Resolve a hostname to an IP address
§Parameters
host
: The hostname to resolve
§Returns
Ok(in_addr)
: The IP address of the hostnameErr(())
: If the hostname could not be resolved
§Errors
DnsError::HostnameResolutionFailed
: The hostname could not be resolved. This may happen if the connection of the socket fails, or if the DNS server does not answer the query, or any other error occurs
Sourcepub fn dns(&self) -> SocketAddr
pub fn dns(&self) -> SocketAddr
Get the SocketAddr
of the DNS server
Trait Implementations§
Source§impl ResolveAddr for DnsResolver
impl ResolveAddr for DnsResolver
Source§impl ResolveHostname for DnsResolver
impl ResolveHostname for DnsResolver
Source§fn resolve_hostname(&mut self, hostname: &str) -> Result<SocketAddr, DnsError>
fn resolve_hostname(&mut self, hostname: &str) -> Result<SocketAddr, DnsError>
Resolve a hostname to an IP address
§Parameters
host
: The hostname to resolve
§Returns
Ok(SocketAddr)
: The IP address of the hostnameErr(DnsError)
: If the hostname could not be resolved
§Errors
DnsError::HostnameResolutionFailed
: The hostname could not be resolved. This may happen if the connection of the socket fails, or if the DNS server does not answer the query, or any other error occurs
type Error = DnsError
impl DnsResolver for DnsResolver
Auto Trait Implementations§
impl Freeze for DnsResolver
impl RefUnwindSafe for DnsResolver
impl !Send for DnsResolver
impl !Sync for DnsResolver
impl Unpin for DnsResolver
impl UnwindSafe for DnsResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more