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