use core::task; use hyper::client::connect::dns::Name; use std::future::Future; use std::net::SocketAddr; use std::task::Poll; use tower_service::Service; // Trait from hyper to implement DNS resolution for HTTP/3 client. pub trait Resolve { type Addrs: Iterator; type Error: Into>; type Future: Future>; fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll>; fn resolve(&mut self, name: Name) -> Self::Future; } impl Resolve for S where S: Service, S::Response: Iterator, S::Error: Into>, { type Addrs = S::Response; type Error = S::Error; type Future = S::Future; fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { Service::poll_ready(self, cx) } fn resolve(&mut self, name: Name) -> Self::Future { Service::call(self, name) } } pub(super) async fn resolve(resolver: &mut R, name: Name) -> Result where R: Resolve, { futures_util::future::poll_fn(|cx| resolver.poll_ready(cx)).await?; resolver.resolve(name).await }