Skip to content

Commit a49227f

Browse files
committed
doc comment updates
1 parent c65a504 commit a49227f

File tree

8 files changed

+151
-22
lines changed

8 files changed

+151
-22
lines changed

sdk/cosmosdb/azure_data_cosmos/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ clap.workspace = true
3434
workspace = true
3535

3636
[features]
37+
default = ["hmac_rust"]
38+
hmac_rust = ["azure_core/hmac_rust"]
39+
hmac_openssl = ["azure_core/hmac_openssl"]
3740
key-auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens)
41+
42+
[package.metadata.docs.rs]
43+
features = ["key-auth"]
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# azure_data_cosmos
1+
# Azure Cosmos DB SDK for Rust.
22

3-
Azure Cosmos DB Rust SDK.
3+
## Introduction
44

5-
License: MIT
5+
This client library enables client applications to connect to [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) via the NoSQL API. Azure Cosmos DB is a globally distributed, multi-model database service.

sdk/cosmosdb/azure_data_cosmos/examples/cosmosdb_connect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
3131
#[cfg(feature = "key-auth")]
3232
fn create_client(args: &Args) -> CosmosClient {
3333
if let Some(key) = args.key.as_ref() {
34-
CosmosClient::with_shared_key(&args.endpoint, key.clone(), None).unwrap()
34+
CosmosClient::with_key(&args.endpoint, key.clone(), None).unwrap()
3535
} else {
3636
let cred = azure_identity::create_default_credential().unwrap();
3737
CosmosClient::new(&args.endpoint, cred, None).unwrap()

sdk/cosmosdb/azure_data_cosmos/src/clients/cosmos_client.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ pub trait CosmosClientMethods {
2828

2929
impl CosmosClient {
3030
/// Creates a new CosmosClient, using Entra ID authentication.
31+
///
32+
/// # Arguments
33+
///
34+
/// * `endpoint` - The full URL of the Cosmos DB account, for example `https://myaccount.documents.azure.com/`.
35+
/// * `credential` - An implementation of [`TokenCredential`](azure_core::auth::TokenCredential) that can provide an Entra ID token to use when authenticating.
36+
/// * `options` - Optional configuration for the client.
37+
///
38+
/// # Examples
39+
///
40+
/// ```rust,no_run
41+
/// use azure_data_cosmos::CosmosClient;
42+
///
43+
/// let credential = azure_identity::create_default_credential().unwrap();
44+
/// let client = CosmosClient::new("https://myaccount.documents.azure.com/", credential, None).unwrap();
45+
/// ```
3146
pub fn new(
3247
endpoint: impl AsRef<str>,
3348
credential: Arc<dyn TokenCredential>,
@@ -44,9 +59,21 @@ impl CosmosClient {
4459
})
4560
}
4661

47-
/// Creates a new CosmosClient, using shared key authentication.
62+
/// Creates a new CosmosClient, using key authentication.
63+
///
64+
/// # Arguments
65+
///
66+
/// * `endpoint` - The full URL of the Cosmos DB account, for example `https://myaccount.documents.azure.com/`.
67+
/// * `key` - The key to use when authenticating.
68+
/// * `options` - Optional configuration for the client.
69+
///
70+
/// # Examples
71+
///
72+
/// ```rust,no_run
73+
/// let client = CosmosClient::with_shared_key("https://myaccount.documents.azure.com/", "my_key", None)?;
74+
/// ```
4875
#[cfg(feature = "key-auth")]
49-
pub fn with_shared_key(
76+
pub fn with_key(
5077
endpoint: impl AsRef<str>,
5178
key: impl Into<Secret>,
5279
options: Option<CosmosClientOptions>,

sdk/cosmosdb/azure_data_cosmos/src/clients/database_client.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,44 @@ use crate::{CosmosClient, ReadDatabaseOptions};
44
use azure_core::{Context, Request};
55
use url::Url;
66

7+
#[cfg(doc)]
8+
use crate::CosmosClientMethods;
9+
10+
/// Defines the methods provided by a [`DatabaseClient`]
11+
///
12+
/// This trait is intended to allow you to mock out the `DatabaseClient` when testing your application.
13+
/// Rather than depending on `DatabaseClient`, you can depend on a generic parameter constrained by this trait, or an `impl DatabaseClientMethods` type.
714
pub trait DatabaseClientMethods {
15+
/// Reads the properties of the database.
16+
///
17+
/// # Arguments
18+
///
19+
/// * `options` - Optional parameters for the request.
20+
///
21+
/// # Examples
22+
///
23+
/// ```rust,no_run
24+
/// # async fn doc() {
25+
/// use azure_data_cosmos::{CosmosClient, CosmosClientMethods, DatabaseClientMethods};
26+
///
27+
/// let credential = azure_identity::create_default_credential().unwrap();
28+
/// let client = CosmosClient::new("https://myaccount.documents.azure.com/", credential, None).unwrap();
29+
/// let db_client = client.database("my_database");
30+
/// let response = db_client.read(None)
31+
/// .await.unwrap()
32+
/// .deserialize_body()
33+
/// .await.unwrap();
34+
/// # }
35+
/// ```
836
fn read(
937
&self,
1038
options: Option<ReadDatabaseOptions>,
1139
) -> impl std::future::Future<Output = azure_core::Result<azure_core::Response<DatabaseProperties>>>;
1240
}
1341

42+
/// A client for working with a specific database in a Cosmos account.
43+
///
44+
/// You can get a `DatabaseClient` by calling [`CosmosClient::database()`](CosmosClient::database).
1445
pub struct DatabaseClient {
1546
base_url: Url,
1647
root_client: CosmosClient,
@@ -40,7 +71,10 @@ impl DatabaseClient {
4071
impl DatabaseClientMethods for DatabaseClient {
4172
async fn read(
4273
&self,
43-
_options: Option<ReadDatabaseOptions>,
74+
75+
#[allow(unused_variables)]
76+
// This is a documented public API so prefixing with '_' is undesirable.
77+
options: Option<ReadDatabaseOptions>,
4478
) -> azure_core::Result<azure_core::Response<DatabaseProperties>> {
4579
let mut req = Request::new(self.base_url.clone(), azure_core::Method::Get);
4680
let ctx = Context::new().with_value(ResourceType::Databases);
+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
#![doc = include_str!("../README.md")]
2+
// Docs.rs build is done with the nightly compiler, so we can enable nightly features in that build.
3+
// In this case we enable two features:
4+
// - `doc_auto_cfg`: Automatically scans `cfg` attributes and uses them to show those required configurations in the generated documentation.
5+
// - `doc_cfg_hide`: Ignore the `doc` configuration for `doc_auto_cfg`.
6+
// See https://doc.rust-lang.org/rustdoc/unstable-features.html#doc_auto_cfg-automatically-generate-doccfg for more details.
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8+
#![cfg_attr(docsrs, feature(doc_cfg_hide))]
9+
110
mod authorization_policy;
211
mod clients;
3-
pub mod models;
412
mod options;
513

14+
/// Model types sent to and received from the Cosmos API.
15+
pub mod models;
16+
617
pub use clients::*;
718
pub use options::*;

sdk/cosmosdb/azure_data_cosmos/src/models/mod.rs

+29-13
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,50 @@ use serde::{Deserialize, Serialize};
22
use time::error::ComponentRange;
33
use time::OffsetDateTime;
44

5-
#[derive(Debug, Serialize, Deserialize)]
6-
pub struct SystemProperties {
7-
#[serde(rename = "_etag")]
8-
pub etag: Option<azure_core::Etag>,
9-
#[serde(rename = "_self")]
10-
pub self_link: Option<String>,
11-
#[serde(rename = "_rid")]
12-
pub resource_id: Option<String>,
13-
#[serde(rename = "_ts")]
14-
pub last_modified: Option<CosmosTimestamp>,
15-
}
5+
#[cfg(doc)]
6+
use crate::DatabaseClientMethods;
167

8+
/// Represents a timestamp in the format expected by Cosmos DB.
9+
///
10+
/// Cosmos DB timestamps are represented as the number of seconds since the Unix epoch.
11+
/// Use [`CosmosTimestamp::try_into`] implementation to convert this into a [`time::OffsetDateTime`].
1712
#[derive(Serialize, Deserialize, Debug)]
1813
pub struct CosmosTimestamp(i64);
1914

15+
/// Converts a [`CosmosTimestamp`] into a [`OffsetDateTime`].
2016
impl TryInto<OffsetDateTime> for CosmosTimestamp {
2117
type Error = ComponentRange;
2218

19+
/// Attempts to convert this [`CosmosTimestamp`] into a [`OffsetDateTime`].
2320
fn try_into(self) -> Result<OffsetDateTime, Self::Error> {
2421
OffsetDateTime::from_unix_timestamp(self.0)
2522
}
2623
}
2724

25+
/// Properties of a Cosmos DB database.
26+
///
27+
/// Returned by [`DatabaseClient::read()`](crate::DatabaseClient::read()).
2828
#[derive(Debug, Deserialize)]
2929
pub struct DatabaseProperties {
30+
/// The ID of the database.
3031
pub id: String,
3132

32-
#[serde(flatten)]
33-
pub system_properties: SystemProperties,
33+
/// The entity tag associated with the resource.
34+
#[serde(rename = "_etag")]
35+
pub etag: Option<azure_core::Etag>,
36+
37+
/// The self-link associated with the resource.
38+
#[serde(rename = "_self")]
39+
pub self_link: Option<String>,
40+
41+
/// The system-generated unique identifier associated with the resource.
42+
#[serde(rename = "_rid")]
43+
pub resource_id: Option<String>,
44+
45+
/// A [`CosmosTimestamp`] representing the last modified time of the resource.
46+
#[serde(rename = "_ts")]
47+
pub last_modified: Option<CosmosTimestamp>,
3448
}
49+
50+
// TODO: Migrate to derive macro once https://github.com/Azure/azure-sdk-for-rust/pull/1772 lands.
3551
azure_core::json_model!(DatabaseProperties);

sdk/cosmosdb/azure_data_cosmos/src/options/mod.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,72 @@
11
use azure_core::ClientOptions;
22

3+
/// Options used when creating a [`CosmosClient`](crate::CosmosClient).
4+
///
5+
/// NOTE: There are currently no options to set on this type.
6+
/// It exists to enable future extensibility.
37
#[derive(Clone, Debug, Default)]
48
pub struct CosmosClientOptions {
59
pub(crate) client_options: ClientOptions,
610
}
711

812
impl CosmosClientOptions {
13+
/// Creates a new [`CosmosClientOptionsBuilder`](builders::CosmosClientOptionsBuilder) that can be used to construct a [`CosmosClientOptions`].
14+
///
15+
/// # Examples
16+
///
17+
/// ```rust
18+
/// let options = azure_data_cosmos::ReadDatabaseOptions::builder().build();
19+
/// ```
920
pub fn builder() -> builders::CosmosClientOptionsBuilder {
1021
builders::CosmosClientOptionsBuilder::default()
1122
}
1223
}
1324

25+
/// Options to be passed to [`DatabaseClientMethods::read()`](crate::DatabaseClientMethods::read()).
26+
///
27+
/// NOTE: There are currently no options to set on this type.
28+
/// It exists to enable future extensibility.
1429
#[derive(Clone, Debug, Default)]
1530
pub struct ReadDatabaseOptions {}
1631

17-
impl ReadDatabaseOptions {}
32+
impl ReadDatabaseOptions {
33+
/// Creates a new [`ReadDatabaseOptionsBuilder`](builders::ReadDatabaseOptionsBuilder) that can be used to construct a [`ReadDatabaseOptions`].
34+
///
35+
/// # Examples
36+
///
37+
/// ```rust
38+
/// let options = azure_data_cosmos::ReadDatabaseOptions::builder().build();
39+
/// ```
40+
pub fn builder() -> builders::ReadDatabaseOptionsBuilder {
41+
builders::ReadDatabaseOptionsBuilder::default()
42+
}
43+
}
1844

45+
/// Builders for Cosmos-related options structs.
1946
pub mod builders {
2047
use crate::{CosmosClientOptions, ReadDatabaseOptions};
2148

49+
/// Builder used to construct a [`CosmosClientOptions`].
2250
#[derive(Default)]
2351
pub struct CosmosClientOptionsBuilder(CosmosClientOptions);
2452

2553
impl CosmosClientOptionsBuilder {
54+
/// Builds a [`CosmosClientOptions`] object from the builder.
55+
///
56+
/// This does not consume the builder, and can be called multiple times.
2657
pub fn build(&self) -> CosmosClientOptions {
2758
self.0.clone()
2859
}
2960
}
3061

62+
/// Builder used to construct a [`ReadDatabaseOptions`].
3163
#[derive(Default)]
3264
pub struct ReadDatabaseOptionsBuilder(ReadDatabaseOptions);
3365

3466
impl ReadDatabaseOptionsBuilder {
67+
/// Builds a [`CosmosClientOptions`] object from the builder.
68+
///
69+
/// This does not consume the builder, and can be called multiple times.
3570
pub fn build(&self) -> ReadDatabaseOptions {
3671
self.0.clone()
3772
}

0 commit comments

Comments
 (0)