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
use crate::erase::DynConnector;
use aws_smithy_async::rt::sleep::AsyncSleep;
use aws_smithy_types::timeout::TimeoutConfig;
use std::{fmt::Debug, sync::Arc};
pub type MakeConnectorFn =
dyn Fn(&HttpSettings, 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: &HttpSettings,
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 HttpSettings {
pub timeout_config: TimeoutConfig,
}
impl HttpSettings {
pub fn with_timeout_config(mut self, timeout_config: TimeoutConfig) -> Self {
self.timeout_config = timeout_config;
self
}
}