ClientBuilder

Struct ClientBuilder 

Source
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 endpoint
  • credentials(): Authentication credentials

§Optional Configuration

  • retry_config(): Retry behavior for transient failures
  • cache_config(): Local caching configuration
  • tls_config(): Custom TLS settings
  • degradation_config(): Graceful degradation behavior
  • timeout(): 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>

Source

pub fn new() -> Self

Creates a new client builder.

Source§

impl<C> ClientBuilder<NoUrl, C>

Source

pub fn url(self, url: impl Into<String>) -> ClientBuilder<HasUrl, C>

Sets the InferaDB API URL.

§Arguments
  • url - The API endpoint (e.g., https://api.inferadb.com)
§Example
let builder = Client::builder()
    .url("https://api.inferadb.com");
Source§

impl<U> ClientBuilder<U, NoCredentials>

Source

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>

Source

pub fn retry_config(self, config: RetryConfig) -> Self

Sets the retry configuration.

§Example
use inferadb::RetryConfig;

let builder = builder.retry_config(
    RetryConfig::new().with_max_retries(5)
);
Source

pub fn cache_config(self, config: CacheConfig) -> Self

Sets the cache configuration.

§Example
use inferadb::CacheConfig;
use std::time::Duration;

let builder = builder.cache_config(
    CacheConfig::enabled().with_ttl(Duration::from_secs(60))
);
Source

pub fn tls_config(self, config: TlsConfig) -> Self

Sets the TLS configuration.

§Example
use inferadb::TlsConfig;

let builder = builder.tls_config(
    TlsConfig::new().with_ca_cert_file("/path/to/ca.crt")
);
Source

pub fn insecure(self) -> Self

Disables TLS certificate verification and allows HTTP connections.

WARNING: This is insecure and should only be used for local development. Never use this in production.

§Example
let client = Client::builder()
    .url("http://localhost:8080")
    .insecure()
    .credentials(credentials)
    .build()
    .await?;
Source

pub fn degradation_config(self, config: DegradationConfig) -> Self

Sets the degradation configuration.

§Example
use inferadb::{DegradationConfig, FailureMode};

let builder = builder.degradation_config(
    DegradationConfig::fail_closed()
);
Source

pub fn timeout(self, timeout: Duration) -> Self

Sets the request timeout.

This timeout applies to individual API requests, not including retries.

§Example
use std::time::Duration;

let builder = builder.timeout(Duration::from_secs(10));
Source

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 unavailable
  • RestOnly: Use REST only
  • PreferGrpc: 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);
Source

pub fn pool_config(self, config: PoolConfig) -> Self

Sets the connection pool configuration.

Controls connection pooling behavior for the transport.

§Example
use inferadb::PoolConfig;
use std::time::Duration;

let builder = builder.pool_config(
    PoolConfig::default()
        .with_max_connections(20)
        .with_pool_timeout(Duration::from_secs(30))
);
Source§

impl ClientBuilder<HasUrl, HasCredentials>

Source

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?;
Source

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§

Source§

impl Default for ClientBuilder<NoUrl, NoCredentials>

Source§

fn default() -> Self

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

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>
where UrlState: Send, CredentialsState: Send,

§

impl<UrlState, CredentialsState> Sync for ClientBuilder<UrlState, CredentialsState>
where UrlState: Sync, CredentialsState: Sync,

§

impl<UrlState, CredentialsState> Unpin for ClientBuilder<UrlState, CredentialsState>
where UrlState: Unpin, CredentialsState: Unpin,

§

impl<UrlState, CredentialsState> UnwindSafe for ClientBuilder<UrlState, CredentialsState>
where UrlState: UnwindSafe, CredentialsState: UnwindSafe,

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> From<T> for T

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 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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

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