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, ErrorKind as IoErrorKind};
12 use std::net::ToSocketAddrs;
13
14 #[non_exhaustive]
18 #[derive(Debug, Default)]
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::new(
35 IoErrorKind::Other,
36 join_failure,
37 ))),
38 Ok(Ok(dns_result)) => {
39 Ok(dns_result.into_iter().map(|addr| addr.ip()).collect())
40 }
41 Ok(Err(dns_failure)) => Err(ResolveDnsError::new(dns_failure)),
42 }
43 })
44 }
45 }
46}
47
48#[cfg(all(feature = "rt-tokio", not(target_family = "wasm")))]
49pub use self::tokio::TokioDnsResolver;