1 | use futures_util::future::FutureExt; |
2 | use hyper::client::connect::dns::{GaiResolver as HyperGaiResolver, Name}; |
3 | use hyper::service::Service; |
4 | |
5 | use crate::dns::{Addrs, Resolve, Resolving}; |
6 | use crate::error::BoxError; |
7 | |
8 | #[derive (Debug)] |
9 | pub struct GaiResolver(HyperGaiResolver); |
10 | |
11 | impl GaiResolver { |
12 | pub fn new() -> Self { |
13 | Self(HyperGaiResolver::new()) |
14 | } |
15 | } |
16 | |
17 | impl Default for GaiResolver { |
18 | fn default() -> Self { |
19 | GaiResolver::new() |
20 | } |
21 | } |
22 | |
23 | impl Resolve for GaiResolver { |
24 | fn resolve(&self, name: Name) -> Resolving { |
25 | let this: &mut GaiResolver = &mut self.0.clone(); |
26 | Box::pin(Service::<Name>::call(self:this, req:name).map(|result: Result| { |
27 | result |
28 | .map(|addrs| -> Addrs { Box::new(addrs) }) |
29 | .map_err(|err: Error| -> BoxError { Box::new(err) }) |
30 | })) |
31 | } |
32 | } |
33 | |