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