rw_aws_sdk_ec2/client/
customize.rs1pub(crate) mod internal {
3 pub type BoxFuture<T> = ::std::pin::Pin<::std::boxed::Box<dyn ::std::future::Future<Output = T> + ::std::marker::Send>>;
4
5 pub type SendResult<T, E> =
6 ::std::result::Result<T, ::aws_smithy_runtime_api::client::result::SdkError<E, ::aws_smithy_runtime_api::client::orchestrator::HttpResponse>>;
7
8 pub trait CustomizableSend<T, E>: ::std::marker::Send + ::std::marker::Sync {
9 fn send(self, config_override: crate::config::Builder) -> BoxFuture<SendResult<T, E>>;
13 }
14}
15pub struct CustomizableOperation<T, E, B> {
17 customizable_send: B,
18 config_override: ::std::option::Option<crate::config::Builder>,
19 interceptors: Vec<::aws_smithy_runtime_api::client::interceptors::SharedInterceptor>,
20 runtime_plugins: Vec<::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin>,
21 _output: ::std::marker::PhantomData<T>,
22 _error: ::std::marker::PhantomData<E>,
23}
24
25impl<T, E, B> CustomizableOperation<T, E, B> {
26 #[allow(dead_code)] pub(crate) fn new(customizable_send: B) -> Self {
29 Self {
30 customizable_send,
31 config_override: ::std::option::Option::None,
32 interceptors: vec![],
33 runtime_plugins: vec![],
34 _output: ::std::marker::PhantomData,
35 _error: ::std::marker::PhantomData,
36 }
37 }
38
39 pub fn interceptor(mut self, interceptor: impl ::aws_smithy_runtime_api::client::interceptors::Intercept + 'static) -> Self {
46 self.interceptors
47 .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(interceptor));
48 self
49 }
50
51 #[allow(unused)]
53 pub(crate) fn runtime_plugin(mut self, runtime_plugin: impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin + 'static) -> Self {
54 self.runtime_plugins
55 .push(::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin::new(runtime_plugin));
56 self
57 }
58
59 pub fn map_request<F, MapE>(mut self, f: F) -> Self
61 where
62 F: ::std::ops::Fn(
63 ::aws_smithy_runtime_api::client::orchestrator::HttpRequest,
64 ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, MapE>
65 + ::std::marker::Send
66 + ::std::marker::Sync
67 + 'static,
68 MapE: ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
69 {
70 self.interceptors
71 .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
72 ::aws_smithy_runtime::client::interceptors::MapRequestInterceptor::new(f),
73 ));
74 self
75 }
76
77 pub fn mutate_request<F>(mut self, f: F) -> Self
79 where
80 F: ::std::ops::Fn(&mut ::aws_smithy_runtime_api::client::orchestrator::HttpRequest) + ::std::marker::Send + ::std::marker::Sync + 'static,
81 {
82 self.interceptors
83 .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
84 ::aws_smithy_runtime::client::interceptors::MutateRequestInterceptor::new(f),
85 ));
86 self
87 }
88
89 pub fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
101 self.config_override = Some(config_override.into());
102 self
103 }
104
105 pub async fn send(self) -> crate::client::customize::internal::SendResult<T, E>
107 where
108 E: std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
109 B: crate::client::customize::internal::CustomizableSend<T, E>,
110 {
111 let mut config_override = self.config_override.unwrap_or_default();
112 self.interceptors.into_iter().for_each(|interceptor| {
113 config_override.push_interceptor(interceptor);
114 });
115 self.runtime_plugins.into_iter().for_each(|plugin| {
116 config_override.push_runtime_plugin(plugin);
117 });
118
119 self.customizable_send.send(config_override).await
120 }
121}