Crate c_ares_resolver
source ·Expand description
DNS resolvers built on c-ares
, for asynchronous DNS requests.
This crate provides three resolver types - the Resolver
, the FutureResolver
, and the
BlockingResolver
:
-
The
Resolver
is the thinnest wrapper around the underlyingc-ares
library. It returns answers via callbacks. The other resolvers are built on top of this. -
The
FutureResolver
returns answers asfutures::Future
s. -
The
BlockingResolver
isn’t asynchronous at all - as the name suggests, it blocks until the lookup completes.
On all resolvers:
-
methods like
query_xxx
correspond to thec-ares
functionares_query
, which “initiates a single-question DNS query”. -
methods like
search_xxx
correspond to thec-ares
functionares_search
, which “initiates a series of single-question DNS queries … using the channel’s search domains as well as a host alias file given by the HOSTALIAS environment variable”.
See c-ares
documentation for more details.
Example
extern crate c_ares_resolver;
extern crate futures;
extern crate tokio;
use std::error::Error;
use futures::future::Future;
fn main() {
let resolver = c_ares_resolver::FutureResolver::new().unwrap();
let query = resolver
.query_a("google.com")
.map_err(|e| println!("Lookup failed with error '{}'", e.description()))
.map(|result| println!("{}", result));
tokio::run(query);
}
Further examples showing how to use the library can be found here.
Structs
FutureResolver
.futures::Future
s.c_ares::HostResults
.c_ares::NameInfoResult
.