aws_smithy_runtime/client/dns/
tokio.rs1use aws_smithy_runtime_api::client::dns::{DnsFuture, ResolveDns, ResolveDnsError};
7use std::io::{Error as IoError, ErrorKind as IoErrorKind};
8use std::net::ToSocketAddrs;
9
10#[non_exhaustive]
14#[derive(Debug, Default)]
15pub struct TokioDnsResolver;
16
17impl TokioDnsResolver {
18 pub fn new() -> Self {
20 Self
21 }
22}
23
24impl ResolveDns for TokioDnsResolver {
25 fn resolve_dns<'a>(&'a self, name: &'a str) -> DnsFuture<'a> {
26 let name = name.to_string();
27 DnsFuture::new(async move {
28 let result = tokio::task::spawn_blocking(move || (name, 0).to_socket_addrs()).await;
29 match result {
30 Err(join_failure) => Err(ResolveDnsError::new(IoError::new(
31 IoErrorKind::Other,
32 join_failure,
33 ))),
34 Ok(Ok(dns_result)) => Ok(dns_result.into_iter().map(|addr| addr.ip()).collect()),
35 Ok(Err(dns_failure)) => Err(ResolveDnsError::new(dns_failure)),
36 }
37 })
38 }
39}