Crate c_ares_resolver [] [src]

A convenient wrapper for the c-ares library.

The c-ares crate provides a safe wrapper around the underlying C library, but it's relatively hard work to use: the user needs to drive the polling of file descriptors according to c-ares demands, which likely involves writing something close to a full-blown event loop.

This crate does that hard work for you so that the presented API is much more straightforward. Simply create a Resolver, and make your query - providing a callback to be called when the query completes.

This crate also provides a FutureResolver. Queries on this object return futures::Future objects, and don't use callbacks.

Additionally, this crate provides a BlockingResolver. Usually if you're using c-ares, it's because you care about high-performance, asynchronous code. But sometimes you'd just like to make a query with as little ceremony as possible, and you're willing to have your code block while you do it. In such cases the BlockingResolver is the most convenient option.

On all resolvers:

  • methods like query_xxx correspond to the c-ares function ares_query, which "initiates a single-question DNS query"

  • methods like search_xxx correspond to the c-ares function ares_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.


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
        .map_err(|e| println!("Lookup failed with error '{}'", e.description()))
        .map(|result| println!("{}", result));

Further examples showing how to use the library can be found here.



A blocking DNS resolver.


The type of future returned by methods on the FutureResolver.


An asynchronous DNS resolver, which returns results as futures::Futures.


An owned version of c_ares::HostResults.


An owned version of c_ares::NameInfoResult.


Used to configure the behaviour of the resolver.


An asynchronous DNS resolver, which returns results via callbacks.



Error codes that the library might return.