rw_aws_sdk_ec2/client/
customize.rs

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