1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::erase::DynConnector;
use aws_smithy_async::rt::sleep::AsyncSleep;
use aws_smithy_types::timeout::TimeoutConfig;
use std::time::Duration;
use std::{fmt::Debug, sync::Arc};
pub type MakeConnectorFn =
dyn Fn(&ConnectorSettings, Option<Arc<dyn AsyncSleep>>) -> Option<DynConnector> + Send + Sync;
#[derive(Clone)]
pub enum HttpConnector {
Prebuilt(Option<DynConnector>),
ConnectorFn(Arc<MakeConnectorFn>),
}
impl Debug for HttpConnector {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Prebuilt(Some(connector)) => {
write!(f, "Prebuilt({:?})", connector)
}
Self::Prebuilt(None) => {
write!(f, "Prebuilt(None)")
}
Self::ConnectorFn(_) => {
write!(f, "ConnectorFn(<function pointer>)")
}
}
}
}
impl HttpConnector {
pub fn connector(
&self,
settings: &ConnectorSettings,
sleep: Option<Arc<dyn AsyncSleep>>,
) -> Option<DynConnector> {
match self {
HttpConnector::Prebuilt(conn) => conn.clone(),
HttpConnector::ConnectorFn(func) => func(settings, sleep),
}
}
}
#[non_exhaustive]
#[derive(Default, Debug)]
pub struct ConnectorSettingsBuilder {
connect_timeout: Option<Duration>,
read_timeout: Option<Duration>,
}
impl ConnectorSettingsBuilder {
pub fn new() -> Self {
Default::default()
}
pub fn connect_timeout(mut self, connect_timeout: Duration) -> Self {
self.connect_timeout = Some(connect_timeout);
self
}
pub fn set_connect_timeout(&mut self, connect_timeout: Option<Duration>) -> &mut Self {
self.connect_timeout = connect_timeout;
self
}
pub fn read_timeout(mut self, read_timeout: Duration) -> Self {
self.read_timeout = Some(read_timeout);
self
}
pub fn set_read_timeout(&mut self, read_timeout: Option<Duration>) -> &mut Self {
self.read_timeout = read_timeout;
self
}
pub fn build(self) -> ConnectorSettings {
ConnectorSettings {
connect_timeout: self.connect_timeout,
read_timeout: self.read_timeout,
}
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ConnectorSettings {
connect_timeout: Option<Duration>,
read_timeout: Option<Duration>,
}
impl ConnectorSettings {
pub fn builder() -> ConnectorSettingsBuilder {
Default::default()
}
pub fn connect_timeout(&self) -> Option<Duration> {
self.connect_timeout
}
pub fn read_timeout(&self) -> Option<Duration> {
self.read_timeout
}
#[doc(hidden)]
pub fn from_timeout_config(timeout_config: &TimeoutConfig) -> Self {
Self {
connect_timeout: timeout_config.connect_timeout(),
read_timeout: timeout_config.read_timeout(),
}
}
}