1use futures_util::future::FutureExt;
2use hyper::client::connect::dns::{GaiResolver as HyperGaiResolver, Name};
3use hyper::service::Service;
4
5use crate::dns::{Addrs, Resolve, Resolving};
6use crate::error::BoxError;
7
8#[derive(Debug)]
9pub struct GaiResolver(HyperGaiResolver);
10
11impl GaiResolver {
12 pub fn new() -> Self {
13 Self(HyperGaiResolver::new())
14 }
15}
16
17impl Default for GaiResolver {
18 fn default() -> Self {
19 GaiResolver::new()
20 }
21}
22
23impl 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