ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder<F, Cr> { /* private fields */ }
Expand description

A generic builder for clients.

In the Google Cloud client libraries for Rust a “client” represents a connection to a specific service. Each client library defines one or more client types. All the clients are initialized using a ClientBuilder.

Applications obtain a builder with the correct generic types using the builder() method on each client:

use examples::Client; // Placeholder for examples
let builder = Client::builder();

To create a client with the default configuration just invoke the .build() method:

use examples::Client; // Placeholder for examples
let client = Client::builder().build().await?;

As usual, the builder offers several method to configure the client, and a .build() method to construct the client:

use examples::Client; // Placeholder for examples
let client = Client::builder()
    .with_endpoint("http://private.googleapis.com")
    .build().await?;

Implementations§

Source§

impl<F, Cr> ClientBuilder<F, Cr>

Source

pub async fn build<C>(self) -> Result<C>
where F: ClientFactory<Client = C, Credentials = Cr>,

Creates a new client.

use examples::Client; // Placeholder for examples
let client = Client::builder()
    .build().await?;
Source

pub fn with_endpoint<V: Into<String>>(self, v: V) -> Self

Sets the endpoint.

use examples::Client; // Placeholder for examples
let client = Client::builder()
    .with_endpoint("http://private.googleapis.com")
    .build().await?;
Source

pub fn with_tracing(self) -> Self

Enables tracing.

The client libraries can be dynamically instrumented with the Tokio tracing framework. Setting this flag enables this instrumentation.

use examples::Client; // Placeholder for examples
let client = Client::builder()
    .with_tracing()
    .build().await?;
Source

pub fn with_credentials<T: Into<Cr>>(self, v: T) -> Self

Configure the authentication credentials.

Most Google Cloud services require authentication, though some services allow for anonymous access, and some services provide emulators where no authentication is required. More information about valid credentials types can be found in the google-cloud-auth crate documentation.

use examples::Client; // Placeholder for examples
// Placeholder, normally use google_cloud_auth::credentials
use examples::credentials;
let client = Client::builder()
    .with_credentials(
        credentials::mds::Builder::new()
            .scopes(["https://www.googleapis.com/auth/cloud-platform.read-only"])
            .build())
    .build().await?;
Source

pub fn with_retry_policy<V: Into<RetryPolicyArg>>(self, v: V) -> Self

Configure the retry policy.

The client libraries can automatically retry operations that fail. The retry policy controls what errors are considered retryable, sets limits on the number of attempts or the time trying to make attempts.

use examples::Client; // Placeholder for examples
use gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
let client = Client::builder()
    .with_retry_policy(AlwaysRetry.with_attempt_limit(3))
    .build().await?;
Source

pub fn with_backoff_policy<V: Into<BackoffPolicyArg>>(self, v: V) -> Self

Configure the retry backoff policy.

The client libraries can automatically retry operations that fail. The backoff policy controls how long to wait in between retry attempts.

use examples::Client; // Placeholder for examples
use gax::exponential_backoff::ExponentialBackoff;
use std::time::Duration;
let policy = ExponentialBackoff::default();
let client = Client::builder()
    .with_backoff_policy(policy)
    .build().await?;
Source

pub fn with_retry_throttler<V: Into<RetryThrottlerArg>>(self, v: V) -> Self

Configure the retry throttler.

Advanced applications may want to configure a retry throttler to [Address Cascading Failures] and when Handling Overload conditions. The client libraries throttle their retry loop, using a policy to control the throttling algorithm. Use this method to fine tune or customize the default retry throtler.

use examples::Client; // Placeholder for examples
use gax::retry_throttler::AdaptiveThrottler;
let client = Client::builder()
    .with_retry_throttler(AdaptiveThrottler::default())
    .build().await?;
Source

pub fn with_polling_error_policy<V: Into<PollingErrorPolicyArg>>( self, v: V, ) -> Self

Configure the polling error policy.

Some clients support long-running operations, the client libraries can automatically poll these operations until they complete. Polling may fail due to transient errors and applications may want to continue the polling loop despite such errors. The polling error policy controls which errors are treated as recoverable, and may limit the number of attempts and/or the total time polling the operation.

use examples::Client; // Placeholder for examples
use gax::polling_error_policy::Aip194Strict;
use gax::polling_error_policy::PollingErrorPolicyExt;
use std::time::Duration;
let client = Client::builder()
    .with_polling_error_policy(Aip194Strict
        .with_time_limit(Duration::from_secs(15 * 60))
        .with_attempt_limit(50))
    .build().await?;
Source

pub fn with_polling_backoff_policy<V: Into<PollingBackoffPolicyArg>>( self, v: V, ) -> Self

Configure the polling backoff policy.

Some clients support long-running operations, the client libraries can automatically poll these operations until they complete. The polling backoff policy controls how long the client waits between polling attempts.

use examples::Client; // Placeholder for examples
use gax::exponential_backoff::ExponentialBackoff;
use std::time::Duration;
let policy = ExponentialBackoff::default();
let client = Client::builder()
    .with_polling_backoff_policy(policy)
    .build().await?;

Trait Implementations§

Source§

impl<F: Clone, Cr: Clone> Clone for ClientBuilder<F, Cr>

Source§

fn clone(&self) -> ClientBuilder<F, Cr>

Returns a duplicate 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<F: Debug, Cr: Debug> Debug for ClientBuilder<F, Cr>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, Cr> Freeze for ClientBuilder<F, Cr>
where F: Freeze, Cr: Freeze,

§

impl<F, Cr> !RefUnwindSafe for ClientBuilder<F, Cr>

§

impl<F, Cr> Send for ClientBuilder<F, Cr>
where F: Send, Cr: Send,

§

impl<F, Cr> Sync for ClientBuilder<F, Cr>
where F: Sync, Cr: Sync,

§

impl<F, Cr> Unpin for ClientBuilder<F, Cr>
where F: Unpin, Cr: Unpin,

§

impl<F, Cr> !UnwindSafe for ClientBuilder<F, Cr>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V