Struct trust_dns_resolver::AsyncResolver

source ·
pub struct AsyncResolver<P: ConnectionProvider> { /* private fields */ }
Expand description

An asynchronous resolver for DNS generic over async Runtimes.

Creating a AsyncResolver returns a new handle and a future that should be spawned on an executor to drive the background work. The lookup methods on AsyncResolver request lookups from the background task.

The futures returned by a AsyncResolver and the corresponding background task need not be spawned on the same executor, or be in the same thread. Additionally, one background task may have any number of handles; calling clone() on a handle will create a new handle linked to the same background task.

NOTE If lookup futures returned by a AsyncResolver and the background future are spawned on two separate CurrentThread executors, one thread cannot run both executors simultaneously, so the run or block_on functions will cause the thread to deadlock. If both the background work and the lookup futures are intended to be run on the same thread, they should be spawned on the same executor.

The background task manages the name server pool and other state used to drive lookups. When this future is spawned on an executor, it will first construct and configure the necessary client state, before checking for any incoming lookup requests, handling them, and yielding. It will continue to do so as long as there are still any AsyncResolver handle linked to it. When all of its AsyncResolvers have been dropped, the background future will finish.

Implementations§

source§

impl AsyncResolver<GenericConnector<TokioRuntimeProvider>>

source

pub fn tokio(config: ResolverConfig, options: ResolverOpts) -> Self

Construct a new Tokio based AsyncResolver with the provided configuration.

§Arguments
  • config - configuration, name_servers, etc. for the Resolver
  • options - basic lookup options for the resolver
§Returns

A tuple containing the new AsyncResolver and a future that drives the background task that runs resolutions for the AsyncResolver. See the documentation for AsyncResolver for more information on how to use the background future.

source

pub fn tokio_from_system_conf() -> Result<Self, ResolveError>

Constructs a new Tokio based Resolver with the system configuration.

This will use /etc/resolv.conf on Unix OSes and the registry on Windows.

source§

impl<R: ConnectionProvider> AsyncResolver<R>

source

pub fn new(config: ResolverConfig, options: ResolverOpts, provider: R) -> Self

Construct a new generic AsyncResolver with the provided configuration.

see [TokioAsyncResolver::tokio(..)] instead.

§Arguments
  • config - configuration, name_servers, etc. for the Resolver
  • options - basic lookup options for the resolver
§Returns

A tuple containing the new AsyncResolver and a future that drives the background task that runs resolutions for the AsyncResolver. See the documentation for AsyncResolver for more information on how to use the background future.

source

pub fn from_system_conf(runtime: R) -> Result<Self, ResolveError>

Constructs a new Resolver with the system configuration.

see [TokioAsyncResolver::tokio_from_system_conf(..)] instead.

This will use /etc/resolv.conf on Unix OSes and the registry on Windows.

source

pub fn clear_cache(&self)

Flushes/Removes all entries from the cache

source§

impl<P: ConnectionProvider> AsyncResolver<P>

source

pub fn new_with_conn( config: ResolverConfig, options: ResolverOpts, conn_provider: P, ) -> Self

Construct a new AsyncResolver with the provided configuration.

§Arguments
  • config - configuration, name_servers, etc. for the Resolver
  • options - basic lookup options for the resolver
§Returns

A tuple containing the new AsyncResolver and a future that drives the background task that runs resolutions for the AsyncResolver. See the documentation for AsyncResolver for more information on how to use the background future.

source

pub fn from_system_conf_with_provider( conn_provider: P, ) -> Result<Self, ResolveError>

Constructs a new Resolver with the system configuration.

This will use /etc/resolv.conf on Unix OSes and the registry on Windows.

source

pub async fn lookup<N: IntoName>( &self, name: N, record_type: RecordType, ) -> Result<Lookup, ResolveError>

Generic lookup for any RecordType

WARNING this interface may change in the future, see if one of the specializations would be better.

§Arguments
  • name - name of the record to lookup, if name is not a valid domain name, an error will be returned
  • record_type - type of record to lookup, all RecordData responses will be filtered to this type
§Returns
source

pub async fn lookup_ip<N: IntoName + TryParseIp>( &self, host: N, ) -> Result<LookupIp, ResolveError>

Performs a dual-stack DNS lookup for the IP for the given hostname.

See the configuration and options parameters for controlling the way in which A(Ipv4) and AAAA(Ipv6) lookups will be performed. For the least expensive query a fully-qualified-domain-name, FQDN, which ends in a final ., e.g. www.example.com., will only issue one query. Anything else will always incur the cost of querying the ResolverConfig::domain and ResolverConfig::search.

§Arguments
  • host - string hostname, if this is an invalid hostname, an error will be returned.
source

pub fn set_hosts(&mut self, hosts: Option<Hosts>)

Customizes the static hosts used in this resolver.

source

pub async fn reverse_lookup( &self, query: IpAddr, ) -> Result<ReverseLookup, ResolveError>

Performs a lookup for the associated type.

§Arguments
  • query - a type which can be converted to Name via From.
source

pub async fn ipv4_lookup<N: IntoName>( &self, query: N, ) -> Result<Ipv4Lookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn ipv6_lookup<N: IntoName>( &self, query: N, ) -> Result<Ipv6Lookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn mx_lookup<N: IntoName>( &self, query: N, ) -> Result<MxLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn ns_lookup<N: IntoName>( &self, query: N, ) -> Result<NsLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn soa_lookup<N: IntoName>( &self, query: N, ) -> Result<SoaLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn srv_lookup<N: IntoName>( &self, query: N, ) -> Result<SrvLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn tlsa_lookup<N: IntoName>( &self, query: N, ) -> Result<TlsaLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error
source

pub async fn txt_lookup<N: IntoName>( &self, query: N, ) -> Result<TxtLookup, ResolveError>

Performs a lookup for the associated type.

hint queries that end with a ‘.’ are fully qualified names and are cheaper lookups

§Arguments
  • query - a string which parses to a domain name, failure to parse will return an error

Trait Implementations§

source§

impl<P: Clone + ConnectionProvider> Clone for AsyncResolver<P>

source§

fn clone(&self) -> AsyncResolver<P>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<P: ConnectionProvider> Debug for AsyncResolver<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for AsyncResolver<P>

§

impl<P> !RefUnwindSafe for AsyncResolver<P>

§

impl<P> Send for AsyncResolver<P>

§

impl<P> Sync for AsyncResolver<P>

§

impl<P> Unpin for AsyncResolver<P>

§

impl<P> !UnwindSafe for AsyncResolver<P>

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more