Add this skill
npx mdskills install sickn33/azure-cosmos-rustWell-structured SDK reference with clear examples and client hierarchy guidance
1---2name: azure-cosmos-rust3description: |4 Azure Cosmos DB SDK for Rust (NoSQL API). Use for document CRUD, queries, containers, and globally distributed data.5 Triggers: "cosmos db rust", "CosmosClient rust", "container", "document rust", "NoSQL rust", "partition key".6package: azure_data_cosmos7---89# Azure Cosmos DB SDK for Rust1011Client library for Azure Cosmos DB NoSQL API — globally distributed, multi-model database.1213## Installation1415```sh16cargo add azure_data_cosmos azure_identity17```1819## Environment Variables2021```bash22COSMOS_ENDPOINT=https://<account>.documents.azure.com:443/23COSMOS_DATABASE=mydb24COSMOS_CONTAINER=mycontainer25```2627## Authentication2829```rust30use azure_identity::DeveloperToolsCredential;31use azure_data_cosmos::CosmosClient;3233let credential = DeveloperToolsCredential::new(None)?;34let client = CosmosClient::new(35 "https://<account>.documents.azure.com:443/",36 credential.clone(),37 None,38)?;39```4041## Client Hierarchy4243| Client | Purpose | Get From |44|--------|---------|----------|45| `CosmosClient` | Account-level operations | Direct instantiation |46| `DatabaseClient` | Database operations | `client.database_client()` |47| `ContainerClient` | Container/item operations | `database.container_client()` |4849## Core Workflow5051### Get Database and Container Clients5253```rust54let database = client.database_client("myDatabase");55let container = database.container_client("myContainer");56```5758### Create Item5960```rust61use serde::{Serialize, Deserialize};6263#[derive(Serialize, Deserialize)]64struct Item {65 pub id: String,66 pub partition_key: String,67 pub value: String,68}6970let item = Item {71 id: "1".into(),72 partition_key: "partition1".into(),73 value: "hello".into(),74};7576container.create_item("partition1", item, None).await?;77```7879### Read Item8081```rust82let response = container.read_item("partition1", "1", None).await?;83let item: Item = response.into_model()?;84```8586### Replace Item8788```rust89let mut item: Item = container.read_item("partition1", "1", None).await?.into_model()?;90item.value = "updated".into();9192container.replace_item("partition1", "1", item, None).await?;93```9495### Patch Item9697```rust98use azure_data_cosmos::models::PatchDocument;99100let patch = PatchDocument::default()101 .with_add("/newField", "newValue")?102 .with_remove("/oldField")?;103104container.patch_item("partition1", "1", patch, None).await?;105```106107### Delete Item108109```rust110container.delete_item("partition1", "1", None).await?;111```112113## Key Auth (Optional)114115Enable key-based authentication with feature flag:116117```sh118cargo add azure_data_cosmos --features key_auth119```120121## Best Practices1221231. **Always specify partition key** — required for point reads and writes1242. **Use `into_model()?`** — to deserialize responses into your types1253. **Derive `Serialize` and `Deserialize`** — for all document types1264. **Use Entra ID auth** — prefer `DeveloperToolsCredential` over key auth1275. **Reuse client instances** — clients are thread-safe and reusable128129## Reference Links130131| Resource | Link |132|----------|------|133| API Reference | https://docs.rs/azure_data_cosmos |134| Source Code | https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/cosmos/azure_data_cosmos |135| crates.io | https://crates.io/crates/azure_data_cosmos |136
Full transparency — inspect the skill content before installing.