aws_sdk_sts/client/customize.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3
4
5
6
7
8
9
10
11
12
13/// `CustomizableOperation` allows for configuring a single operation invocation before it is sent.
14 pub struct CustomizableOperation<T, E, B> {
15 customizable_send: B,
16 config_override: ::std::option::Option<crate::config::Builder>,
17 interceptors: Vec<::aws_smithy_runtime_api::client::interceptors::SharedInterceptor>,
18 runtime_plugins: Vec<::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin>,
19 _output: ::std::marker::PhantomData<T>,
20 _error: ::std::marker::PhantomData<E>,
21 }
22
23 impl<T, E, B> CustomizableOperation<T, E, B> {
24 /// Creates a new `CustomizableOperation` from `customizable_send`.
25 #[allow(dead_code)] // unused when a service does not provide any operations
26 pub(crate) fn new(customizable_send: B) -> Self {
27 Self {
28 customizable_send,
29 config_override: ::std::option::Option::None,
30 interceptors: vec![],
31 runtime_plugins: vec![],
32 _output: ::std::marker::PhantomData,
33 _error: ::std::marker::PhantomData
34 }
35 }
36
37 pub(crate) fn execute<U>(self, f: impl ::std::ops::FnOnce(B, crate::config::Builder) -> U) -> U {
38 let mut config_override = self.config_override.unwrap_or_default();
39 self.interceptors.into_iter().for_each(|interceptor| {
40 config_override.push_interceptor(interceptor);
41 });
42 self.runtime_plugins.into_iter().for_each(|plugin| {
43 config_override.push_runtime_plugin(plugin);
44 });
45 f(self.customizable_send, config_override)
46 }
47
48 /// Adds an [interceptor](::aws_smithy_runtime_api::client::interceptors::Intercept) that runs at specific stages of the request execution pipeline.
49 ///
50 /// Note that interceptors can also be added to `CustomizableOperation` by `config_override`,
51 /// `map_request`, and `mutate_request` (the last two are implemented via interceptors under the hood).
52 /// The order in which those user-specified operation interceptors are invoked should not be relied upon
53 /// as it is an implementation detail.
54 pub fn interceptor(mut self, interceptor: impl ::aws_smithy_runtime_api::client::interceptors::Intercept + 'static) -> Self {
55 self.interceptors.push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(interceptor));
56 self
57 }
58
59 /// Adds a runtime plugin.
60 #[allow(unused)]
61 pub(crate) fn runtime_plugin(mut self, runtime_plugin: impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin + 'static) -> Self {
62 self.runtime_plugins.push(::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin::new(runtime_plugin));
63 self
64 }
65
66 /// Allows for customizing the operation's request.
67 pub fn map_request<F, MapE>(mut self, f: F) -> Self
68 where
69 F: ::std::ops::Fn(::aws_smithy_runtime_api::client::orchestrator::HttpRequest) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, MapE>
70 + ::std::marker::Send
71 + ::std::marker::Sync
72 + 'static,
73 MapE: ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
74 {
75 self.interceptors.push(
76 ::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
77 ::aws_smithy_runtime::client::interceptors::MapRequestInterceptor::new(f),
78 ),
79 );
80 self
81 }
82
83 /// Convenience for `map_request` where infallible direct mutation of request is acceptable.
84 pub fn mutate_request<F>(mut self, f: F) -> Self
85 where
86 F: ::std::ops::Fn(&mut ::aws_smithy_runtime_api::client::orchestrator::HttpRequest) + ::std::marker::Send + ::std::marker::Sync + 'static,
87 {
88 self.interceptors.push(
89 ::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
90 ::aws_smithy_runtime::client::interceptors::MutateRequestInterceptor::new(f),
91 ),
92 );
93 self
94 }
95
96 /// Overrides config for a single operation invocation.
97 ///
98 /// `config_override` is applied to the operation configuration level.
99 /// The fields in the builder that are `Some` override those applied to the service
100 /// configuration level. For instance,
101 ///
102 /// | Config A | overridden by Config B | = Config C |
103 /// |--------------------|------------------------|--------------------|
104 /// | field_1: None, | field_1: Some(v2), | field_1: Some(v2), |
105 /// | field_2: Some(v1), | field_2: Some(v2), | field_2: Some(v2), |
106 /// | field_3: Some(v1), | field_3: None, | field_3: Some(v1), |
107 pub fn config_override(
108 mut self,
109 config_override: impl ::std::convert::Into<crate::config::Builder>,
110 ) -> Self {
111 self.config_override = Some(config_override.into());
112 self
113 }
114
115 /// Sends the request and returns the response.
116 pub async fn send(
117 self,
118 ) -> crate::client::customize::internal::SendResult<T, E>
119 where
120 E: std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
121 B: crate::client::customize::internal::CustomizableSend<T, E>,
122 {
123 self.execute(|sender, config|sender.send(config)).await
124 }
125
126
127 }
128
129pub(crate) mod internal;
130