aws_sdk_kms/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.
4pub 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
13impl<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
46            .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(interceptor));
47        self
48    }
49
50    /// Adds a runtime plugin.
51    #[allow(unused)]
52    pub(crate) fn runtime_plugin(mut self, runtime_plugin: impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin + 'static) -> Self {
53        self.runtime_plugins
54            .push(::aws_smithy_runtime_api::client::runtime_plugin::SharedRuntimePlugin::new(runtime_plugin));
55        self
56    }
57
58    /// Allows for customizing the operation's request.
59    pub fn map_request<F, MapE>(mut self, f: F) -> Self
60    where
61        F: ::std::ops::Fn(
62                ::aws_smithy_runtime_api::client::orchestrator::HttpRequest,
63            ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, MapE>
64            + ::std::marker::Send
65            + ::std::marker::Sync
66            + 'static,
67        MapE: ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
68    {
69        self.interceptors
70            .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
71                ::aws_smithy_runtime::client::interceptors::MapRequestInterceptor::new(f),
72            ));
73        self
74    }
75
76    /// Convenience for `map_request` where infallible direct mutation of request is acceptable.
77    pub fn mutate_request<F>(mut self, f: F) -> Self
78    where
79        F: ::std::ops::Fn(&mut ::aws_smithy_runtime_api::client::orchestrator::HttpRequest) + ::std::marker::Send + ::std::marker::Sync + 'static,
80    {
81        self.interceptors
82            .push(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::new(
83                ::aws_smithy_runtime::client::interceptors::MutateRequestInterceptor::new(f),
84            ));
85        self
86    }
87
88    /// Overrides config for a single operation invocation.
89    ///
90    /// `config_override` is applied to the operation configuration level.
91    /// The fields in the builder that are `Some` override those applied to the service
92    /// configuration level. For instance,
93    ///
94    /// | Config A           | overridden by Config B | = Config C         |
95    /// |--------------------|------------------------|--------------------|
96    /// | field_1: None,     | field_1: Some(v2),     | field_1: Some(v2), |
97    /// | field_2: Some(v1), | field_2: Some(v2),     | field_2: Some(v2), |
98    /// | field_3: Some(v1), | field_3: None,         | field_3: Some(v1), |
99    pub fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
100        self.config_override = Some(config_override.into());
101        self
102    }
103
104    /// Sends the request and returns the response.
105    pub async fn send(self) -> crate::client::customize::internal::SendResult<T, E>
106    where
107        E: std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static,
108        B: crate::client::customize::internal::CustomizableSend<T, E>,
109    {
110        self.execute(|sender, config| sender.send(config)).await
111    }
112}
113
114pub(crate) mod internal;