一键导入
azure-cosmos-rust
// Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data. Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust".
// Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data. Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust".
Guide for creating effective skills for AI coding agents working with Azure SDKs and Microsoft Foundry services. Use when creating new skills or updating existing skills.
Azure Event Hubs library for Rust. Send and receive events for streaming data ingestion and batch processing. Triggers: "event hubs rust", "ProducerClient rust", "ConsumerClient rust", "send event rust", "streaming rust", "eventhub rust".
Azure Identity library for Rust. Microsoft Entra ID authentication for all Azure SDK clients. Triggers: "azure identity rust", "DeveloperToolsCredential", "authentication rust", "managed identity rust", "credential rust", "Entra ID rust".
Azure Key Vault Certificates library for Rust. Create, manage, and use X.509 certificates including self-signed and CA-issued. Triggers: "keyvault certificates rust", "CertificateClient rust", "create certificate rust", "self-signed certificate rust", "X.509 rust".
Azure Key Vault Keys library for Rust. Create, manage, and use cryptographic keys including RSA, EC, and HSM-protected keys. Triggers: "keyvault keys rust", "KeyClient rust", "create key rust", "encrypt rust", "wrap key rust", "sign rust".
Azure Key Vault Secrets library for Rust. Store and retrieve secrets, passwords, and API keys. Triggers: "keyvault secrets rust", "SecretClient rust", "get secret rust", "set secret rust", "list secrets rust".
| name | azure-cosmos-rust |
| description | Azure Cosmos DB library for Rust (NoSQL API). Document CRUD, containers, and globally distributed data. Triggers: "cosmos db rust", "CosmosClient rust", "document crud rust", "NoSQL rust", "partition key rust". |
| license | MIT |
| metadata | {"author":"Microsoft","package":"azure_data_cosmos"} |
Client library for Azure Cosmos DB NoSQL API — document CRUD, containers, and globally distributed data.
Use this skill when:
IMPORTANT: Only use the official
azure_data_cosmoscrate published by the azure-sdk crates.io user. Do NOT use the unofficialazure_cosmosorazure_sdk_for_rustcommunity crates. Official crates use underscores in names and none have version 0.21.0.
cargo add azure_data_cosmos azure_identity tokio
Do not add
azure_coredirectly toCargo.toml. It is re-exported byazure_data_cosmos.
COSMOS_ENDPOINT=https://<account>.documents.azure.com/ # Required for all operations
use azure_identity::DeveloperToolsCredential;
use azure_data_cosmos::{CosmosClient, CosmosAccountReference, CosmosAccountEndpoint};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Local dev: DeveloperToolsCredential. Production: use ManagedIdentityCredential.
let credential: std::sync::Arc<dyn azure_core::credentials::TokenCredential> =
DeveloperToolsCredential::new(None)?;
let endpoint: CosmosAccountEndpoint = "https://<account>.documents.azure.com/"
.parse()?;
let account = CosmosAccountReference::with_credential(endpoint, credential);
let client = CosmosClient::builder().build(account).await?;
Ok(())
}
| Client | Purpose | Access |
|---|---|---|
CosmosClient | Account-level operations | CosmosClient::builder().build(account).await? |
DatabaseClient | Database operations | client.database_client("db") |
ContainerClient | Container/item operations | database.container_client("c").await |
use serde::{Serialize, Deserialize};
use azure_data_cosmos::CosmosClient;
#[derive(Serialize, Deserialize)]
struct Item {
pub id: String,
pub partition_key: String,
pub value: String,
}
async fn crud(client: CosmosClient) -> Result<(), Box<dyn std::error::Error>> {
let container = client
.database_client("myDatabase")
.container_client("myContainer")
.await;
let item = Item {
id: "1".into(),
partition_key: "pk1".into(),
value: "hello".into(),
};
// Create
container.create_item("pk1", item, None).await?;
// Read
let resp = container.read_item("pk1", "1", None).await?;
let mut item: Item = resp.into_model()?;
// Update
item.value = "updated".into();
container.replace_item("pk1", "1", item, None).await?;
// Delete
container.delete_item("pk1", "1", None).await?;
Ok(())
}
Enable account key authentication with the feature flag:
cargo add azure_data_cosmos --features key_auth
For Entra ID auth, assign one of these built-in Cosmos DB roles:
| Role | Access |
|---|---|
Cosmos DB Built-in Data Reader | Read-only |
Cosmos DB Built-in Data Contributor | Read/write |
DeveloperToolsCredential for local development and ManagedIdentityCredential for production. The Rust SDK does not support DefaultAzureCredential, so explicitly use the appropriate credential in each environment.create_item(), read_item(), replace_item(), and delete_item() call.CosmosClient — clients are thread-safe; create once, share across tasks| Resource | Link |
|---|---|
| API Reference | https://docs.rs/azure_data_cosmos |
| crates.io | https://crates.io/crates/azure_data_cosmos |