c_ares_resolver/
lib.rs

1//! DNS resolvers built on [`c-ares`](https://c-ares.org), for asynchronous DNS requests.
2//!
3//! This crate provides three resolver types - the `Resolver`, the `FutureResolver`, and the
4//! `BlockingResolver`:
5//!
6//! - The `Resolver` is the thinnest wrapper around the underlying `c-ares` library.  It returns
7//!   answers via callbacks.  The other resolvers are built on top of this.
8//!
9//! - The `FutureResolver` returns answers as `std::future::Future`s.
10//!
11//! - The `BlockingResolver` isn't asynchronous at all - as the name suggests, it blocks until the
12//!   lookup completes.
13//!
14//! On all resolvers:
15//!
16//! - methods like `query_xxx` correspond to the `c-ares` function `ares_query`, which "initiates
17//!   a single-question DNS query".
18//!
19//! - methods like `search_xxx` correspond to the `c-ares` function `ares_search`, which
20//!   "initiates a series of single-question DNS queries ... using the channel's search domains as
21//!   well as a host alias file given by the HOSTALIAS environment variable".
22//!
23//! See [`c-ares` documentation](https://c-ares.org/docs.html) for more details.
24//!
25//! # Example
26//!
27//! ```rust
28//! extern crate c_ares_resolver;
29//! extern crate futures_executor;
30//! use futures_executor::block_on;
31//!
32//! fn main() {
33//!     let resolver = c_ares_resolver::FutureResolver::new().unwrap();
34//!     let query = resolver.query_a("google.com");
35//!     let response = block_on(query);
36//!     match response {
37//!         Ok(result) => println!("{}", result),
38//!         Err(e) => println!("Lookup failed with error '{}'", e)
39//!     }
40//! }
41//! ```
42//!
43//! Further examples showing how to use the library can be found
44//! [here](https://github.com/dimbleby/c-ares-resolver/tree/main/examples).
45#![deny(missing_docs)]
46
47mod blockingresolver;
48mod error;
49mod eventloop;
50mod futureresolver;
51mod host;
52mod nameinfo;
53mod resolver;
54
55#[cfg(test)]
56mod tests;
57
58pub use crate::blockingresolver::BlockingResolver;
59pub use crate::error::Error;
60pub use crate::futureresolver::{CAresFuture, FutureResolver};
61pub use crate::host::HostResults;
62pub use crate::nameinfo::NameInfoResult;
63pub use crate::resolver::{Options, Resolver};