Struct DnsResolver

Source
pub struct DnsResolver { /* private fields */ }
Expand description

A DNS resolver

Implementations§

Source§

impl DnsResolver

Source

pub fn new(dns: SocketAddr) -> Result<Self, DnsError>

Create a new DNS resolver

§Parameters
§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
Source

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
Source

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 hostname
  • Err(()): 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
Source

pub fn dns(&self) -> SocketAddr

Get the SocketAddr of the DNS server

Trait Implementations§

Source§

impl ResolveAddr for DnsResolver

Source§

type Error = DnsError

Source§

fn resolve_addr(&mut self, _addr: in_addr) -> Result<String, DnsError>

Resolve an IP address to a hostname Read more
Source§

impl ResolveHostname for DnsResolver

Source§

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 hostname
  • Err(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
Source§

type Error = DnsError

Source§

impl DnsResolver for DnsResolver

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V