|
1 | 1 | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 |
| -use crate::client::Handle; |
3 | 2 | pub use aws_smithy_http::operation::Operation;
|
4 |
| -pub use aws_smithy_http::operation::Request; |
5 |
| -pub use aws_smithy_http::operation::Response; |
6 |
| -pub use aws_smithy_http::retry::ClassifyRetry; |
7 |
| -pub use aws_smithy_types::retry::RetryKind; |
| 3 | + pub use aws_smithy_http::operation::Request; |
| 4 | + pub use aws_smithy_http::operation::Response; |
| 5 | + pub use aws_smithy_http::retry::ClassifyRetry; |
| 6 | + pub use aws_smithy_types::retry::RetryKind; |
| 7 | +use crate::client::Handle; |
| 8 | + |
| 9 | + use aws_smithy_http::body::SdkBody; |
| 10 | + use aws_smithy_http::result::SdkError; |
8 | 11 |
|
9 |
| -use aws_smithy_http::body::SdkBody; |
10 |
| -use aws_smithy_http::result::SdkError; |
| 12 | + use std::convert::Infallible; |
| 13 | + use std::sync::Arc; |
11 | 14 |
|
12 |
| -use std::convert::Infallible; |
13 |
| -use std::sync::Arc; |
| 15 | + /// A wrapper type for [`Operation`](aws_smithy_http::operation::Operation)s that allows for |
| 16 | + /// customization of the operation before it is sent. A `CustomizableOperation` may be sent |
| 17 | + /// by calling its [`.send()`][crate::client::customize::CustomizableOperation::send] method. |
| 18 | + #[derive(Debug)] |
| 19 | + pub struct CustomizableOperation<O, Retry> { |
| 20 | + pub(crate) handle: Arc<Handle>, |
| 21 | + pub(crate) operation: Operation<O, Retry>, |
| 22 | + } |
14 | 23 |
|
15 |
| -/// A wrapper type for [`Operation`](aws_smithy_http::operation::Operation)s that allows for |
16 |
| -/// customization of the operation before it is sent. A `CustomizableOperation` may be sent |
17 |
| -/// by calling its [`.send()`][crate::client::customize::CustomizableOperation::send] method. |
18 |
| -#[derive(Debug)] |
19 |
| -pub struct CustomizableOperation<O, Retry> { |
20 |
| - pub(crate) handle: Arc<Handle>, |
21 |
| - pub(crate) operation: Operation<O, Retry>, |
22 |
| -} |
| 24 | + impl<O, Retry> CustomizableOperation<O, Retry> |
| 25 | + where |
| 26 | + |
| 27 | + { |
| 28 | + /// Allows for customizing the operation's request |
| 29 | + pub fn map_request<E>( |
| 30 | + mut self, |
| 31 | + f: impl FnOnce(http::Request<SdkBody>) -> Result<http::Request<SdkBody>, E>, |
| 32 | + ) -> Result<Self, E> { |
| 33 | + let (request, response) = self.operation.into_request_response(); |
| 34 | + let request = request.augment(|req, _props| f(req))?; |
| 35 | + self.operation = Operation::from_parts(request, response); |
| 36 | + Ok(self) |
| 37 | + } |
23 | 38 |
|
24 |
| -impl<O, Retry> CustomizableOperation<O, Retry> { |
25 |
| - /// Allows for customizing the operation's request |
26 |
| - pub fn map_request<E>( |
27 |
| - mut self, |
28 |
| - f: impl FnOnce(http::Request<SdkBody>) -> Result<http::Request<SdkBody>, E>, |
29 |
| - ) -> Result<Self, E> { |
30 |
| - let (request, response) = self.operation.into_request_response(); |
31 |
| - let request = request.augment(|req, _props| f(req))?; |
32 |
| - self.operation = Operation::from_parts(request, response); |
33 |
| - Ok(self) |
34 |
| - } |
| 39 | + /// Convenience for `map_request` where infallible direct mutation of request is acceptable |
| 40 | + pub fn mutate_request(self, f: impl FnOnce(&mut http::Request<SdkBody>)) -> Self { |
| 41 | + self.map_request(|mut req| { |
| 42 | + f(&mut req); |
| 43 | + Result::<_, Infallible>::Ok(req) |
| 44 | + }) |
| 45 | + .expect("infallible") |
| 46 | + } |
35 | 47 |
|
36 |
| - /// Convenience for `map_request` where infallible direct mutation of request is acceptable |
37 |
| - pub fn mutate_request(self, f: impl FnOnce(&mut http::Request<SdkBody>)) -> Self { |
38 |
| - self.map_request(|mut req| { |
39 |
| - f(&mut req); |
40 |
| - Result::<_, Infallible>::Ok(req) |
41 |
| - }) |
42 |
| - .expect("infallible") |
43 |
| - } |
| 48 | + /// Allows for customizing the entire operation |
| 49 | + pub fn map_operation<E>( |
| 50 | + mut self, |
| 51 | + f: impl FnOnce(Operation<O, Retry>) -> Result<Operation<O, Retry>, E>, |
| 52 | + ) -> Result<Self, E> { |
| 53 | + self.operation = f(self.operation)?; |
| 54 | + Ok(self) |
| 55 | + } |
44 | 56 |
|
45 |
| - /// Allows for customizing the entire operation |
46 |
| - pub fn map_operation<E>( |
47 |
| - mut self, |
48 |
| - f: impl FnOnce(Operation<O, Retry>) -> Result<Operation<O, Retry>, E>, |
49 |
| - ) -> Result<Self, E> { |
50 |
| - self.operation = f(self.operation)?; |
51 |
| - Ok(self) |
52 |
| - } |
| 57 | + /// Direct access to read the HTTP request |
| 58 | + pub fn request(&self) -> &http::Request<SdkBody> { |
| 59 | + self.operation.request() |
| 60 | + } |
53 | 61 |
|
54 |
| - /// Direct access to read the HTTP request |
55 |
| - pub fn request(&self) -> &http::Request<SdkBody> { |
56 |
| - self.operation.request() |
57 |
| - } |
| 62 | + /// Direct access to mutate the HTTP request |
| 63 | + pub fn request_mut(&mut self) -> &mut http::Request<SdkBody> { |
| 64 | + self.operation.request_mut() |
| 65 | + } |
| 66 | + } |
58 | 67 |
|
59 |
| - /// Direct access to mutate the HTTP request |
60 |
| - pub fn request_mut(&mut self) -> &mut http::Request<SdkBody> { |
61 |
| - self.operation.request_mut() |
62 |
| - } |
63 |
| -} |
| 68 | +impl<O, Retry> CustomizableOperation<O, Retry> |
| 69 | + where |
| 70 | + |
| 71 | + { |
| 72 | + /// Sends this operation's request |
| 73 | + pub async fn send<T, E>(self) -> Result<T, SdkError<E>> |
| 74 | + where |
| 75 | + E: std::error::Error + Send + Sync + 'static, |
| 76 | + O: aws_smithy_http::response::ParseHttpResponse<Output = Result<T, E>> + Send + Sync + Clone + 'static, |
| 77 | + Retry: aws_smithy_http::retry::ClassifyRetry<aws_smithy_http::result::SdkSuccess<T>, aws_smithy_http::result::SdkError<E>> + Send + Sync + Clone, |
| 78 | + { |
| 79 | + self.handle.client.call(self.operation).await |
| 80 | + } |
| 81 | + } |
64 | 82 |
|
65 |
| -impl<O, Retry> CustomizableOperation<O, Retry> { |
66 |
| - /// Sends this operation's request |
67 |
| - pub async fn send<T, E>(self) -> Result<T, SdkError<E>> |
68 |
| - where |
69 |
| - E: std::error::Error + Send + Sync + 'static, |
70 |
| - O: aws_smithy_http::response::ParseHttpResponse<Output = Result<T, E>> |
71 |
| - + Send |
72 |
| - + Sync |
73 |
| - + Clone |
74 |
| - + 'static, |
75 |
| - Retry: aws_smithy_http::retry::ClassifyRetry< |
76 |
| - aws_smithy_http::result::SdkSuccess<T>, |
77 |
| - aws_smithy_http::result::SdkError<E>, |
78 |
| - > + Send |
79 |
| - + Sync |
80 |
| - + Clone, |
81 |
| - { |
82 |
| - self.handle.client.call(self.operation).await |
83 |
| - } |
84 |
| -} |
0 commit comments