Struct aws_smithy_client::Builder
source · pub struct Builder<C = (), M = (), R = Standard> { /* private fields */ }
Expand description
A builder that provides more customization options when constructing a Client
.
To start, call Builder::new
. Then, chain the method calls to configure the Builder
.
When configured to your liking, call Builder::build
. The individual methods have additional
documentation.
Implementations§
source§impl<C, M> Builder<C, M>where
C: Default,
M: Default,
impl<C, M> Builder<C, M>where C: Default, M: Default,
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new builder. This does not specify a connector or middleware. It uses the standard retry mechanism.
source§impl<M, R> Builder<(), M, R>
impl<M, R> Builder<(), M, R>
sourcepub fn rustls_connector(
self,
connector_settings: ConnectorSettings
) -> Builder<DynConnector, M, R>
pub fn rustls_connector( self, connector_settings: ConnectorSettings ) -> Builder<DynConnector, M, R>
Connect to the service over HTTPS using Rustls using dynamic dispatch.
source§impl<M, R> Builder<(), M, R>
impl<M, R> Builder<(), M, R>
sourcepub fn dyn_https_connector(
self,
connector_settings: ConnectorSettings
) -> Builder<DynConnector, M, R>
pub fn dyn_https_connector( self, connector_settings: ConnectorSettings ) -> Builder<DynConnector, M, R>
Create a Smithy client builder with an HTTPS connector and the standard retry policy over the default middleware implementation.
For convenience, this constructor type-erases the concrete TLS connector backend used using
dynamic dispatch. This comes at a slight runtime performance cost. See
DynConnector
for details. To avoid that overhead, use
Builder::rustls_connector
or [Builder::native_tls_connector
] instead.
source§impl<M, R> Builder<(), M, R>
impl<M, R> Builder<(), M, R>
sourcepub fn connector<C>(self, connector: C) -> Builder<C, M, R>
pub fn connector<C>(self, connector: C) -> Builder<C, M, R>
Specify the connector for the eventual client to use.
The connector dictates how requests are turned into responses. Normally, this would entail sending the request to some kind of remote server, but in certain settings it’s useful to be able to use a custom connector instead, such as to mock the network for tests.
If you just want to specify a function from request to response instead, use
Builder::connector_fn
.
sourcepub fn connector_fn<F, FF>(self, map: F) -> Builder<ServiceFn<F>, M, R>where
F: Fn(Request<SdkBody>) -> FF + Send,
FF: Future<Output = Result<Response<SdkBody>, ConnectorError>>,
ServiceFn<F>: SmithyConnector,
pub fn connector_fn<F, FF>(self, map: F) -> Builder<ServiceFn<F>, M, R>where F: Fn(Request<SdkBody>) -> FF + Send, FF: Future<Output = Result<Response<SdkBody>, ConnectorError>>, ServiceFn<F>: SmithyConnector,
Use a function that directly maps each request to a response as a connector.
use aws_smithy_client::Builder;
use aws_smithy_http::body::SdkBody;
let client = Builder::new()
.middleware(..)
.connector_fn(|req: http::Request<SdkBody>| {
async move {
Ok(http::Response::new(SdkBody::empty()))
}
})
.build();
source§impl<C, R> Builder<C, (), R>
impl<C, R> Builder<C, (), R>
sourcepub fn middleware<M>(self, middleware: M) -> Builder<C, M, R>
pub fn middleware<M>(self, middleware: M) -> Builder<C, M, R>
Specify the middleware for the eventual client ot use.
The middleware adjusts requests before they are dispatched to the connector. It is responsible for filling in any request parameters that aren’t specified by the Smithy protocol definition, such as those used for routing (like the URL), authentication, and authorization.
The middleware takes the form of a tower::Layer
that wraps the actual connection for
each request. The tower::Service
that the middleware produces must accept requests of
the type aws_smithy_http::operation::Request
and return responses of the type
http::Response<SdkBody>
, most likely by modifying the provided request in place,
passing it to the inner service, and then ultimately returning the inner service’s
response.
If your requests are already ready to be sent and need no adjustment, you can use
tower::layer::util::Identity
as your middleware.
sourcepub fn middleware_fn<F>(self, map: F) -> Builder<C, MapRequestLayer<F>, R>where
F: Fn(Request) -> Request + Clone + Send + Sync + 'static,
pub fn middleware_fn<F>(self, map: F) -> Builder<C, MapRequestLayer<F>, R>where F: Fn(Request) -> Request + Clone + Send + Sync + 'static,
Use a function-like middleware that directly maps each request.
use aws_smithy_client::Builder;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::never::NeverConnector;
use aws_smithy_http::body::SdkBody;
let my_connector = DynConnector::new(
// Your own connector here or use `dyn_https_connector()`
);
let client = Builder::new()
.connector(my_connector)
.middleware_fn(|req: aws_smithy_http::operation::Request| {
req
})
.build();
source§impl<C, M> Builder<C, M, Standard>
impl<C, M> Builder<C, M, Standard>
sourcepub fn retry_policy<R>(self, retry_policy: R) -> Builder<C, M, R>
pub fn retry_policy<R>(self, retry_policy: R) -> Builder<C, M, R>
Specify the retry policy for the eventual client to use.
By default, the Smithy client uses a standard retry policy that works well in most
settings. You can use this method to override that policy with a custom one. A new policy
instance will be instantiated for each request using retry::NewRequestPolicy
. Each
policy instance must implement tower::retry::Policy
.
If you just want to modify the policy configuration for the standard retry policy, use
Builder::set_retry_config
.
source§impl<C, M> Builder<C, M>
impl<C, M> Builder<C, M>
sourcepub fn set_retry_config(&mut self, config: Option<Config>) -> &mut Self
pub fn set_retry_config(&mut self, config: Option<Config>) -> &mut Self
Set the standard retry policy’s configuration. When config
is None
,
the default retry policy will be used.
sourcepub fn retry_config(self, config: Config) -> Self
pub fn retry_config(self, config: Config) -> Self
Set the standard retry policy’s configuration.
sourcepub fn set_operation_timeout_config(
&mut self,
operation_timeout_config: Option<OperationTimeoutConfig>
) -> &mut Self
pub fn set_operation_timeout_config( &mut self, operation_timeout_config: Option<OperationTimeoutConfig> ) -> &mut Self
Set operation timeout config for the client. If operation_timeout_config
is
None
, timeouts will be disabled.
sourcepub fn operation_timeout_config(
self,
operation_timeout_config: OperationTimeoutConfig
) -> Self
pub fn operation_timeout_config( self, operation_timeout_config: OperationTimeoutConfig ) -> Self
Set operation timeout config for the client.
sourcepub fn set_sleep_impl(
&mut self,
async_sleep: Option<Arc<dyn AsyncSleep>>
) -> &mut Self
pub fn set_sleep_impl( &mut self, async_sleep: Option<Arc<dyn AsyncSleep>> ) -> &mut Self
Set the AsyncSleep
function that the Client
will use to create things like timeout futures.
sourcepub fn sleep_impl(self, async_sleep: Arc<dyn AsyncSleep>) -> Self
pub fn sleep_impl(self, async_sleep: Arc<dyn AsyncSleep>) -> Self
Set the AsyncSleep
function that the Client
will use to create things like timeout futures.
source§impl<C, M, R> Builder<C, M, R>
impl<C, M, R> Builder<C, M, R>
sourcepub fn map_connector<F, C2>(self, map: F) -> Builder<C2, M, R>where
F: FnOnce(C) -> C2,
pub fn map_connector<F, C2>(self, map: F) -> Builder<C2, M, R>where F: FnOnce(C) -> C2,
Use a connector that wraps the current connector.
sourcepub fn map_middleware<F, M2>(self, map: F) -> Builder<C, M2, R>where
F: FnOnce(M) -> M2,
pub fn map_middleware<F, M2>(self, map: F) -> Builder<C, M2, R>where F: FnOnce(M) -> M2,
Use a middleware that wraps the current middleware.
source§impl<C, M, R> Builder<C, M, R>where
C: SmithyConnector,
M: SmithyMiddleware<DynConnector> + Send + Sync + 'static,
R: NewRequestPolicy,
impl<C, M, R> Builder<C, M, R>where C: SmithyConnector, M: SmithyMiddleware<DynConnector> + Send + Sync + 'static, R: NewRequestPolicy,
sourcepub fn build_dyn(self) -> DynClient<R>
pub fn build_dyn(self) -> DynClient<R>
Build a type-erased Smithy service Client
.
Note that if you’re using the standard retry mechanism, retry::Standard
, DynClient<R>
is equivalent to Client
with no type arguments.
use aws_smithy_client::{Builder, Client};
struct MyClient {
client: aws_smithy_client::Client,
}
let client = Builder::new()
.https()
.middleware(tower::layer::util::Identity::new())
.build_dyn();
let client = MyClient { client };