#Has anyone managed to implement the
5 messages · Page 1 of 1 (latest)
The current error I'm getting is this. I've tried implementing it without using poll futures (ie. just returning a Box::pin with an async block inside it from CustomResolver) but that also gave some gnarly type errors.
use std::net::SocketAddr;
use hyper::client::connect::dns::Name;
use reqwest::dns::{Addrs, Resolve, Resolving};
use trust_dns_resolver::TokioAsyncResolver;
type BoxError = Box<dyn std::error::Error + Send + Sync>;
struct CustomResolver {
inner: TokioAsyncResolver,
}
impl Resolve for CustomResolver {
fn resolve(&self, name: Name) -> Resolving {
let inner = self.inner.clone();
Box::pin(async move {
match inner.lookup_ip(name.as_str().to_owned()).await {
Ok(x) => Ok(Addrs::from(Box::new(
x.into_iter().map(|ip| SocketAddr::from((ip, 443))),
))),
Err(error) => Err(BoxError::from(error)),
}
})
}
}
as for fixing your example specifically
impl Resolve for CustomResolver {
fn resolve(&self, name: Name) -> Resolving {
let inner = self.inner.clone();
Box::pin(async move {
CustomResolverFuture {
inner: inner.lookup_ip(name.as_str().to_owned()),
}
.await
})
}
}
Ah lovely, yeah I didn't realise I was so close and just needed to move that lookup_ip line inside the block but that makes sense so it can actually own inner for the whole future lifetime