aws_smithy_runtime_api/client/
dns.rs
1use crate::box_error::BoxError;
9use crate::impl_shared_conversions;
10use std::error::Error as StdError;
11use std::fmt;
12use std::net::IpAddr;
13use std::sync::Arc;
14
15#[derive(Debug)]
17pub struct ResolveDnsError {
18 source: BoxError,
19}
20
21impl ResolveDnsError {
22 pub fn new(source: impl Into<BoxError>) -> Self {
24 ResolveDnsError {
25 source: source.into(),
26 }
27 }
28}
29
30impl fmt::Display for ResolveDnsError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "failed to perform DNS lookup")
33 }
34}
35
36impl StdError for ResolveDnsError {
37 fn source(&self) -> Option<&(dyn StdError + 'static)> {
38 Some(&*self.source as _)
39 }
40}
41
42new_type_future! {
43 #[doc = "New-type for the future returned by the [`ResolveDns`] trait."]
44 pub struct DnsFuture<'a, Vec<IpAddr>, ResolveDnsError>;
45}
46
47pub trait ResolveDns: fmt::Debug + Send + Sync {
49 fn resolve_dns<'a>(&'a self, name: &'a str) -> DnsFuture<'a>;
51}
52
53#[derive(Clone, Debug)]
55pub struct SharedDnsResolver(Arc<dyn ResolveDns>);
56
57impl SharedDnsResolver {
58 pub fn new(resolver: impl ResolveDns + 'static) -> Self {
60 Self(Arc::new(resolver))
61 }
62}
63
64impl ResolveDns for SharedDnsResolver {
65 fn resolve_dns<'a>(&'a self, name: &'a str) -> DnsFuture<'a> {
66 self.0.resolve_dns(name)
67 }
68}
69
70impl_shared_conversions!(convert SharedDnsResolver from ResolveDns using SharedDnsResolver::new);
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn check_send() {
78 fn is_send<T: Send>() {}
79 is_send::<DnsFuture<'_>>();
80 }
81}