Skip to main content

CosmosDriverRuntime

Struct CosmosDriverRuntime 

Source
#[non_exhaustive]
pub struct CosmosDriverRuntime { /* private fields */ }
Expand description

The Cosmos DB driver runtime environment.

A runtime represents the global configuration shared across all drivers and connections. It includes connection pool settings, default operation options, and manages singleton driver instances per account.

§Thread Safety

The runtime is thread-safe and can be shared across threads. Each call to create_driver produces a fresh CosmosDriver; drivers built from the same runtime share its long-lived resources (bootstrap transport, metadata caches, CPU monitor, etc.).

§Example

use azure_data_cosmos_driver::driver::{
    CosmosDriverRuntime, CosmosDriverRuntimeBuilder,
};
use azure_data_cosmos_driver::options::{
    DriverOptions, OperationOptions, OperationOptionsBuilder,
};
use azure_data_cosmos_driver::models::AccountReference;
use url::Url;

let operation_options = OperationOptionsBuilder::new()
    .with_max_failover_retry_count(5)
    .build();

let cosmos_runtime = CosmosDriverRuntimeBuilder::new()
    .with_default_operation_options(operation_options)
    .build()
    .await?;

// Create a driver for an account
let account = AccountReference::with_master_key(
    Url::parse("https://myaccount.documents.azure.com:443/").unwrap(),
    "my-key",
);

let driver = cosmos_runtime
    .create_driver(DriverOptions::builder(account).build())
    .await?;

// Later, replace runtime defaults atomically
// cosmos_runtime.set_default_operation_options(new_options);

Implementations§

Source§

impl CosmosDriverRuntime

Source

pub fn builder() -> CosmosDriverRuntimeBuilder

Returns a new builder for creating a runtime.

Source

pub fn client_options(&self) -> &ClientOptions

Returns the HTTP client options.

Source

pub fn connection_pool(&self) -> &ConnectionPoolOptions

Returns the connection pool options.

Source

pub fn proxy_configuration(&self) -> &ProxyConfiguration

Returns the proxy configuration snapshot.

Captures whether proxy is allowed and the proxy environment variable values at client creation time, for diagnostic purposes.

Source

pub fn env_operation_options(&self) -> &Arc<OperationOptions>

Returns the environment-level operation options (populated from env vars at build time).

Source

pub fn env_override_operation_options(&self) -> &Arc<OperationOptions>

Returns the highest-priority kill-switch operation options (populated from the {ENV}_OVERRIDE variants at build time).

Source

pub fn default_operation_options(&self) -> Arc<OperationOptions>

Returns a snapshot of the default operation options.

The returned Arc is a cheap clone of the current value. In-flight readers are unaffected by concurrent calls to set_default_operation_options.

Source

pub fn set_default_operation_options(&self, options: OperationOptions)

Replaces the default operation options atomically.

In-flight operations that already obtained a snapshot via default_operation_options are unaffected.

Source

pub fn user_agent(&self) -> &Arc<UserAgent>

Returns the computed user agent string.

The user agent is automatically computed with a static prefix containing SDK version and platform info, plus an optional suffix derived from user_agent_suffix, workload_id, or correlation_id (in priority order).

Stored as an Arc so CosmosDriver instances without a per-driver suffix override can clone this shared value instead of recomputing the User-Agent.

Source

pub fn workload_id(&self) -> Option<WorkloadId>

Returns the workload identifier.

Source

pub fn correlation_id(&self) -> Option<&CorrelationId>

Returns the correlation ID for client-side metrics.

Source

pub fn user_agent_suffix(&self) -> Option<&UserAgentSuffix>

Returns the user agent suffix.

Source

pub fn wrapping_sdk_identifier(&self) -> Option<&str>

Returns the wrapping-SDK identifier, if one was supplied via CosmosDriverRuntimeBuilder::with_wrapping_sdk_identifier.

Source

pub fn effective_correlation(&self) -> Option<&str>

Returns the effective correlation dimension.

Returns correlation_id if set, otherwise falls back to user_agent_suffix.

Source

pub async fn create_driver( self: &Arc<Self>, driver_options: DriverOptions, ) -> Result<Arc<CosmosDriver>>

Creates a fresh driver bound to this runtime.

Each call returns a new CosmosDriver — the runtime no longer caches drivers by account endpoint. Callers that want a single driver per account must hold onto the returned Arc themselves. Drivers built from the same runtime share runtime-owned resources (bootstrap transport, account-metadata cache, container cache, CPU monitor, etc.).

§Parameters
  • driver_options: Driver-level options, including the account reference.
§Example
use azure_data_cosmos_driver::driver::CosmosDriverRuntime;
use azure_data_cosmos_driver::options::DriverOptions;
use azure_data_cosmos_driver::models::AccountReference;
use url::Url;

let runtime = CosmosDriverRuntime::builder().build().await?;

let account = AccountReference::with_master_key(
    Url::parse("https://myaccount.documents.azure.com:443/").unwrap(),
    "my-key",
);

let driver = runtime
    .create_driver(DriverOptions::builder(account).build())
    .await?;

Trait Implementations§

Source§

impl Debug for CosmosDriverRuntime

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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<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