Struct aws_sdk_s3::client::Builder
source · [−]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
sourceimpl<C, M> Builder<C, M, Standard> where
C: Default,
M: Default,
impl<C, M> Builder<C, M, Standard> where
C: Default,
M: Default,
sourcepub fn new() -> Builder<C, M, Standard>
pub fn new() -> Builder<C, M, Standard>
Construct a new builder. This does not specify a connector or middleware. It uses the standard retry mechanism.
sourceimpl<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();
sourceimpl<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: 'static + Fn(Request) -> Request + Clone + Send + Sync,
pub fn middleware_fn<F>(self, map: F) -> Builder<C, MapRequestLayer<F>, R> where
F: 'static + Fn(Request) -> Request + Clone + Send + Sync,
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()`
);
let client = Builder::new()
.connector(my_connector)
.middleware_fn(|req: aws_smithy_http::operation::Request| {
req
})
.build();
sourceimpl<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
.
sourceimpl<C, M> Builder<C, M, Standard>
impl<C, M> Builder<C, M, Standard>
sourcepub fn set_retry_config(&mut self, config: Config)
pub fn set_retry_config(&mut self, config: Config)
Set the standard retry policy’s configuration.
sourcepub fn set_timeout_config(&mut self, timeout_config: Config)
pub fn set_timeout_config(&mut self, timeout_config: Config)
Set a timeout config for the builder
sourcepub fn set_sleep_impl(
&mut self,
async_sleep: Option<Arc<dyn AsyncSleep + 'static>>
)
pub fn set_sleep_impl(
&mut self,
async_sleep: Option<Arc<dyn AsyncSleep + 'static>>
)
Set the AsyncSleep
function that the Client
will use to create things like timeout futures.
sourcepub fn sleep_impl(
self,
async_sleep: Option<Arc<dyn AsyncSleep + 'static>>
) -> Builder<C, M, Standard>
pub fn sleep_impl(
self,
async_sleep: Option<Arc<dyn AsyncSleep + 'static>>
) -> Builder<C, M, Standard>
Set the AsyncSleep
function that the Client
will use to create things like timeout futures.
sourcepub fn default_async_sleep(self) -> Builder<C, M, Standard>
pub fn default_async_sleep(self) -> Builder<C, M, Standard>
Sets the sleep implementation to default_async_sleep
.
sourceimpl<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.
sourceimpl<C, M, R> Builder<C, M, R> where
C: SmithyConnector,
M: 'static + SmithyMiddleware<DynConnector> + Send + Sync,
R: NewRequestPolicy,
impl<C, M, R> Builder<C, M, R> where
C: SmithyConnector,
M: 'static + SmithyMiddleware<DynConnector> + Send + Sync,
R: NewRequestPolicy,
sourcepub fn build_dyn(self) -> Client<DynConnector, DynMiddleware<DynConnector>, R>
pub fn build_dyn(self) -> Client<DynConnector, DynMiddleware<DynConnector>, 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 };
sourceimpl<M> Builder<DynConnector, M, Standard> where
M: Default,
impl<M> Builder<DynConnector, M, Standard> where
M: Default,
sourcepub fn dyn_https() -> Builder<DynConnector, M, Standard>
pub fn dyn_https() -> Builder<DynConnector, M, Standard>
Create a Smithy client builder with an HTTPS connector and the standard retry policy over the default middleware implementation.
Note: This function does not set a sleep implementation to ensure that default_async_sleep
or set_sleep_impl
is called.
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
or Builder::native_tls
instead.
sourceimpl<M, R> Builder<(), M, R>
impl<M, R> Builder<(), M, R>
sourcepub fn rustls(self) -> Builder<DynConnector, M, R>
pub fn rustls(self) -> Builder<DynConnector, M, R>
Connect to the service over HTTPS using Rustls using dynamic dispatch.
sourceimpl<M, R> Builder<(), M, R>
impl<M, R> Builder<(), M, R>
sourcepub fn native_tls(self) -> Builder<DynConnector, M, R>
pub fn native_tls(self) -> Builder<DynConnector, M, R>
Connect to the service over HTTPS using the native TLS library on your platform using dynamic dispatch.
Trait Implementations
Auto Trait Implementations
impl<C = (), M = (), R = Standard> !RefUnwindSafe for Builder<C, M, R>
impl<C, M, R> Send for Builder<C, M, R> where
C: Send,
M: Send,
R: Send,
impl<C, M, R> Sync for Builder<C, M, R> where
C: Sync,
M: Sync,
R: Sync,
impl<C, M, R> Unpin for Builder<C, M, R> where
C: Unpin,
M: Unpin,
R: Unpin,
impl<C = (), M = (), R = Standard> !UnwindSafe for Builder<C, M, R>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more