aws_smithy_runtime/client/
dns.rs1#[cfg(all(feature = "rt-tokio", not(target_family = "wasm")))]
9mod tokio {
10 use aws_smithy_runtime_api::client::dns::{DnsFuture, ResolveDns, ResolveDnsError};
11 use std::io::Error as IoError;
12 use std::net::ToSocketAddrs;
13
14 #[non_exhaustive]
18 #[derive(Debug, Default, Clone)]
19 pub struct TokioDnsResolver;
20
21 impl TokioDnsResolver {
22 pub fn new() -> Self {
24 Self
25 }
26 }
27
28 impl ResolveDns for TokioDnsResolver {
29 fn resolve_dns<'a>(&'a self, name: &'a str) -> DnsFuture<'a> {
30 let name = name.to_string();
31 DnsFuture::new(async move {
32 let result = tokio::task::spawn_blocking(move || (name, 0).to_socket_addrs()).await;
33 match result {
34 Err(join_failure) => Err(ResolveDnsError::new(IoError::other(join_failure))),
35 Ok(Ok(dns_result)) => {
36 Ok(dns_result.into_iter().map(|addr| addr.ip()).collect())
37 }
38 Ok(Err(dns_failure)) => Err(ResolveDnsError::new(dns_failure)),
39 }
40 })
41 }
42 }
43}
44
45#[cfg(all(feature = "rt-tokio", not(target_family = "wasm")))]
46pub use self::tokio::TokioDnsResolver;