aws_sdk_sts/client/
customize.rs

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