#[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
impl CosmosDriverRuntime
Sourcepub fn builder() -> CosmosDriverRuntimeBuilder
pub fn builder() -> CosmosDriverRuntimeBuilder
Returns a new builder for creating a runtime.
Sourcepub fn client_options(&self) -> &ClientOptions
pub fn client_options(&self) -> &ClientOptions
Returns the HTTP client options.
Sourcepub fn connection_pool(&self) -> &ConnectionPoolOptions
pub fn connection_pool(&self) -> &ConnectionPoolOptions
Returns the connection pool options.
Sourcepub fn proxy_configuration(&self) -> &ProxyConfiguration
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.
Sourcepub fn env_operation_options(&self) -> &Arc<OperationOptions> ⓘ
pub fn env_operation_options(&self) -> &Arc<OperationOptions> ⓘ
Returns the environment-level operation options (populated from env vars at build time).
Sourcepub fn env_override_operation_options(&self) -> &Arc<OperationOptions> ⓘ
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).
Sourcepub fn default_operation_options(&self) -> Arc<OperationOptions> ⓘ
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.
Sourcepub fn set_default_operation_options(&self, options: OperationOptions)
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.
Sourcepub fn user_agent(&self) -> &Arc<UserAgent> ⓘ
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.
Sourcepub fn workload_id(&self) -> Option<WorkloadId>
pub fn workload_id(&self) -> Option<WorkloadId>
Returns the workload identifier.
Sourcepub fn correlation_id(&self) -> Option<&CorrelationId>
pub fn correlation_id(&self) -> Option<&CorrelationId>
Returns the correlation ID for client-side metrics.
Sourcepub fn user_agent_suffix(&self) -> Option<&UserAgentSuffix>
pub fn user_agent_suffix(&self) -> Option<&UserAgentSuffix>
Returns the user agent suffix.
Sourcepub fn wrapping_sdk_identifier(&self) -> Option<&str>
pub fn wrapping_sdk_identifier(&self) -> Option<&str>
Returns the wrapping-SDK identifier, if one was supplied via
CosmosDriverRuntimeBuilder::with_wrapping_sdk_identifier.
Sourcepub fn effective_correlation(&self) -> Option<&str>
pub fn effective_correlation(&self) -> Option<&str>
Returns the effective correlation dimension.
Returns correlation_id if set, otherwise falls back to user_agent_suffix.
Sourcepub async fn create_driver(
self: &Arc<Self>,
driver_options: DriverOptions,
) -> Result<Arc<CosmosDriver>>
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?;