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>
impl<F, Cr> ClientBuilder<F, Cr>
Sourcepub async fn build<C>(self) -> Result<C>where
F: ClientFactory<Client = C, Credentials = Cr>,
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?;Sourcepub fn with_endpoint<V: Into<String>>(self, v: V) -> Self
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?;Sourcepub fn with_tracing(self) -> Self
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?;Sourcepub fn with_credentials<T: Into<Cr>>(self, v: T) -> Self
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?;Sourcepub fn with_retry_policy<V: Into<RetryPolicyArg>>(self, v: V) -> Self
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?;Sourcepub fn with_backoff_policy<V: Into<BackoffPolicyArg>>(self, v: V) -> Self
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?;Sourcepub fn with_retry_throttler<V: Into<RetryThrottlerArg>>(self, v: V) -> Self
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?;Sourcepub fn with_polling_error_policy<V: Into<PollingErrorPolicyArg>>(
self,
v: V,
) -> Self
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?;Sourcepub fn with_polling_backoff_policy<V: Into<PollingBackoffPolicyArg>>(
self,
v: V,
) -> Self
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>
impl<F: Clone, Cr: Clone> Clone for ClientBuilder<F, Cr>
Source§fn clone(&self) -> ClientBuilder<F, Cr>
fn clone(&self) -> ClientBuilder<F, Cr>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more