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, Standard>where C: Default, M: Default,

source

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.

source§

impl<M, R> Builder<(), M, R>

source

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>

source

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>

source

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.

source

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>

source

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.

source

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>

source

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, Standard>

source

pub fn set_retry_config( &mut self, config: Option<Config> ) -> &mut Builder<C, M, Standard>

Set the standard retry policy’s configuration. When config is None, the default retry policy will be used.

source

pub fn retry_config(self, config: Config) -> Builder<C, M, Standard>

Set the standard retry policy’s configuration.

source

pub fn set_operation_timeout_config( &mut self, operation_timeout_config: Option<OperationTimeoutConfig> ) -> &mut Builder<C, M, Standard>

Set operation timeout config for the client. If operation_timeout_config is None, timeouts will be disabled.

source

pub fn operation_timeout_config( self, operation_timeout_config: OperationTimeoutConfig ) -> Builder<C, M, Standard>

Set operation timeout config for the client.

source

pub fn set_sleep_impl( &mut self, async_sleep: Option<Arc<dyn AsyncSleep + 'static>> ) -> &mut Builder<C, M, Standard>

Set the AsyncSleep function that the Client will use to create things like timeout futures.

source

pub fn sleep_impl( self, async_sleep: Arc<dyn AsyncSleep + 'static> ) -> Builder<C, M, Standard>

Set the AsyncSleep function that the Client will use to create things like timeout futures.

source§

impl<C, M, R> Builder<C, M, R>

source

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.

source

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

pub fn build(self) -> Client<C, M, R>

Build a Smithy service Client.

source§

impl<C, M, R> Builder<C, M, R>where C: SmithyConnector, M: SmithyMiddleware<DynConnector> + Send + Sync + 'static, R: NewRequestPolicy,

source

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 };

Trait Implementations§

source§

impl<C, M, R> Clone for Builder<C, M, R>where C: Clone, M: Clone, R: Clone,

source§

fn clone(&self) -> Builder<C, M, R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C, M, R> Debug for Builder<C, M, R>where C: Debug, M: Debug, R: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<C, M> Default for Builder<C, M, Standard>where C: Default, M: Default,

source§

fn default() -> Builder<C, M, Standard>

Returns the “default value” for a type. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more