pub struct ClientBuilder<UrlState, CredentialsState> { /* private fields */ }Expand description
Builder for creating Client instances.
Uses the typestate pattern to ensure required configuration (URL and credentials) is provided at compile time.
§Required Configuration
url(): The InferaDB API endpointcredentials(): Authentication credentials
§Optional Configuration
retry_config(): Retry behavior for transient failurescache_config(): Local caching configurationtls_config(): Custom TLS settingsdegradation_config(): Graceful degradation behaviortimeout(): Request timeout
§Example
ⓘ
use inferadb::{Client, ClientCredentialsConfig, Ed25519PrivateKey};
let client = Client::builder()
.url("https://api.inferadb.com")
.credentials(ClientCredentialsConfig {
client_id: "client_123".into(),
private_key: Ed25519PrivateKey::from_pem_file("key.pem")?,
certificate_id: None,
})
.retry_config(RetryConfig::new().with_max_retries(5))
.timeout(Duration::from_secs(10))
.build()
.await?;Implementations§
Source§impl ClientBuilder<NoUrl, NoCredentials>
impl ClientBuilder<NoUrl, NoCredentials>
Source§impl<C> ClientBuilder<NoUrl, C>
impl<C> ClientBuilder<NoUrl, C>
Source§impl<U> ClientBuilder<U, NoCredentials>
impl<U> ClientBuilder<U, NoCredentials>
Sourcepub fn credentials(
self,
credentials: impl Into<Credentials>,
) -> ClientBuilder<U, HasCredentials>
pub fn credentials( self, credentials: impl Into<Credentials>, ) -> ClientBuilder<U, HasCredentials>
Sets the authentication credentials.
Accepts any type that can be converted into Credentials:
§Example
ⓘ
use inferadb::{ClientCredentialsConfig, Ed25519PrivateKey};
let builder = Client::builder()
.credentials(ClientCredentialsConfig {
client_id: "client_123".into(),
private_key: Ed25519PrivateKey::generate(),
certificate_id: None,
});Source§impl<U, C> ClientBuilder<U, C>
impl<U, C> ClientBuilder<U, C>
Sourcepub fn retry_config(self, config: RetryConfig) -> Self
pub fn retry_config(self, config: RetryConfig) -> Self
Sourcepub fn cache_config(self, config: CacheConfig) -> Self
pub fn cache_config(self, config: CacheConfig) -> Self
Sourcepub fn tls_config(self, config: TlsConfig) -> Self
pub fn tls_config(self, config: TlsConfig) -> Self
Sourcepub fn degradation_config(self, config: DegradationConfig) -> Self
pub fn degradation_config(self, config: DegradationConfig) -> Self
Sourcepub fn transport_strategy(self, strategy: TransportStrategy) -> Self
pub fn transport_strategy(self, strategy: TransportStrategy) -> Self
Sets the transport strategy.
Controls which transport protocol(s) the client uses:
GrpcOnly: Use gRPC only, fail if unavailableRestOnly: Use REST onlyPreferGrpc: Use gRPC with automatic REST fallback (default)
§Example
ⓘ
use inferadb::TransportStrategy;
// Use gRPC only
let builder = builder.transport_strategy(TransportStrategy::GrpcOnly);
// Use REST only
let builder = builder.transport_strategy(TransportStrategy::RestOnly);Sourcepub fn pool_config(self, config: PoolConfig) -> Self
pub fn pool_config(self, config: PoolConfig) -> Self
Source§impl ClientBuilder<HasUrl, HasCredentials>
impl ClientBuilder<HasUrl, HasCredentials>
Sourcepub async fn build(self) -> Result<Client, Error>
pub async fn build(self) -> Result<Client, Error>
Builds the client.
This validates the configuration and establishes the initial connection to the InferaDB service.
§Errors
Returns an error if:
- The URL is invalid
- The credentials are invalid
- The initial connection fails
§Example
ⓘ
let client = Client::builder()
.url("https://api.inferadb.com")
.credentials(credentials)
.build()
.await?;Sourcepub async fn build_with_shutdown(
self,
) -> Result<(Client, ShutdownHandle), Error>
pub async fn build_with_shutdown( self, ) -> Result<(Client, ShutdownHandle), Error>
Builds the client with a shutdown handle.
Returns both the client and a shutdown handle that can be used to initiate graceful shutdown.
§Example
ⓘ
use tokio::signal;
use std::time::Duration;
let (client, shutdown_handle) = Client::builder()
.url("https://api.inferadb.com")
.credentials(credentials)
.build_with_shutdown()
.await?;
tokio::select! {
_ = signal::ctrl_c() => {
shutdown_handle.shutdown_timeout(Duration::from_secs(30)).await;
}
_ = run_server(client) => {}
}Trait Implementations§
Auto Trait Implementations§
impl<UrlState, CredentialsState> Freeze for ClientBuilder<UrlState, CredentialsState>
impl<UrlState, CredentialsState> RefUnwindSafe for ClientBuilder<UrlState, CredentialsState>where
UrlState: RefUnwindSafe,
CredentialsState: RefUnwindSafe,
impl<UrlState, CredentialsState> Send for ClientBuilder<UrlState, CredentialsState>
impl<UrlState, CredentialsState> Sync for ClientBuilder<UrlState, CredentialsState>
impl<UrlState, CredentialsState> Unpin for ClientBuilder<UrlState, CredentialsState>
impl<UrlState, CredentialsState> UnwindSafe for ClientBuilder<UrlState, CredentialsState>where
UrlState: UnwindSafe,
CredentialsState: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request