Skip to content

Commit b5b0d6f

Browse files
authored
RUST-252 Fully document driver with intra-docs links (#97)
1 parent 945e38d commit b5b0d6f

File tree

18 files changed

+249
-93
lines changed

18 files changed

+249
-93
lines changed

src/client/auth/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Contains the types needed to specify the auth configuration for a
2+
//! [`Client`](struct.Client.html).
3+
14
mod scram;
25
#[cfg(test)]
36
mod test;

src/client/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ const DEFAULT_SERVER_SELECTION_TIMEOUT: Duration = Duration::from_secs(30);
3838
/// so it can safely be shared across threads. For example:
3939
///
4040
/// ```rust
41-
///
4241
/// # use mongodb::{Client, error::Result};
43-
///
42+
/// #
4443
/// # fn start_workers() -> Result<()> {
4544
/// let client = Client::with_uri_str("mongodb://example.com")?;
4645
///
@@ -78,7 +77,8 @@ impl Client {
7877
/// Creates a new `Client` connected to the cluster specified by `uri`. `uri` must be a valid
7978
/// MongoDB connection string.
8079
///
81-
/// See the documentation on ClientOptions::parse for more details.
80+
/// See the documentation on
81+
/// [`ClientOptions::parse`](options/struct.ClientOptions.html#method.parse) for more details.
8282
pub fn with_uri_str(uri: &str) -> Result<Self> {
8383
let options = ClientOptions::parse(uri)?;
8484

@@ -104,17 +104,17 @@ impl Client {
104104
}
105105
}
106106

107-
/// Gets the read preference of the `Client`.
107+
/// Gets the default selection criteria the `Client` uses for operations..
108108
pub fn selection_criteria(&self) -> Option<&SelectionCriteria> {
109109
self.inner.options.selection_criteria.as_ref()
110110
}
111111

112-
/// Gets the read concern of the `Client`.
112+
/// Gets the default read concern the `Client` uses for operations.
113113
pub fn read_concern(&self) -> Option<&ReadConcern> {
114114
self.inner.options.read_concern.as_ref()
115115
}
116116

117-
/// Gets the write concern of the `Client`.
117+
/// Gets the default write concern the `Client` uses for operations.
118118
pub fn write_concern(&self) -> Option<&WriteConcern> {
119119
self.inner.options.write_concern.as_ref()
120120
}
@@ -139,11 +139,13 @@ impl Client {
139139
Database::new(self.clone(), name, Some(options))
140140
}
141141

142+
/// Gets information about each database present in the cluster the Client is connected to.
142143
pub fn list_databases(&self, filter: impl Into<Option<Document>>) -> Result<Vec<Document>> {
143144
let op = ListDatabases::new(filter.into(), false);
144145
self.execute_operation(&op, None)
145146
}
146147

148+
/// Gets the names of the databases present in the cluster the Client is connected to.
147149
pub fn list_database_names(&self, filter: impl Into<Option<Document>>) -> Result<Vec<String>> {
148150
let op = ListDatabases::new(filter.into(), true);
149151
match self.execute_operation(&op, None) {

src/client/options/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ lazy_static! {
5151
};
5252
}
5353

54+
/// A hostname:port address pair.
5455
#[derive(Clone, Debug, Eq)]
5556
pub struct StreamAddress {
57+
/// The hostname of the address.
5658
pub hostname: String,
59+
60+
/// The port of the address.
61+
///
62+
/// The default is 27017.
5763
pub port: Option<u16>,
5864
}
5965

@@ -155,7 +161,7 @@ impl fmt::Display for StreamAddress {
155161
}
156162
}
157163

158-
/// Contains the options that can be used to create a new Client.
164+
/// Contains the options that can be used to create a new [`Client`](../struct.Client.html).
159165
#[derive(Clone, Derivative, TypedBuilder)]
160166
#[derivative(Debug, PartialEq)]
161167
pub struct ClientOptions {
@@ -351,6 +357,8 @@ struct ClientOptionsParser {
351357
original_uri: String,
352358
}
353359

360+
/// Specifies whether TLS configuration should be used with the operations that the
361+
/// [`Client`](../struct.Client.html) performs.
354362
#[derive(Clone, Debug, PartialEq)]
355363
pub enum Tls {
356364
Enabled(TlsOptions),
@@ -369,14 +377,27 @@ impl From<TlsOptions> for Option<Tls> {
369377
}
370378
}
371379

380+
/// Specifies the TLS configuration that the [`Client`](../struct.Client.html) should use.
372381
#[derive(Clone, Debug, Default, PartialEq, TypedBuilder)]
373382
pub struct TlsOptions {
383+
/// Whether or not the [`Client`](../struct.Client.html) should return an error if the server
384+
/// presents an invalid certificate. This setting should _not_ be set to `true` in
385+
/// production; it should only be used for testing.
386+
///
387+
/// The default value is to error when the server presents an invalid certificate.
374388
#[builder(default)]
375389
pub allow_invalid_certificates: Option<bool>,
376390

391+
/// The path to the CA file that the [`Client`](../struct.Client.html) should use for TLS. If
392+
/// none is specified, then the driver will use the Mozilla root certificates from the
393+
/// `webpki-roots` crate.
377394
#[builder(default)]
378395
pub ca_file_path: Option<String>,
379396

397+
/// The path to the certificate file that the [`Client`](../struct.Client.html) should present
398+
/// to the server to verify its identify. If none is specified, then the
399+
/// [`Client`](../struct.Client.html) will not attempt to verify its identity to the
400+
/// server.
380401
#[builder(default)]
381402
pub cert_key_file_path: Option<String>,
382403
}

src/cmap/test/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock};
22

33
use serde::{de::Unexpected, Deserialize, Deserializer};
44

5-
use crate::event::cmap::*;
5+
use crate::{event::cmap::*, options::StreamAddress};
66

77
#[derive(Clone, Debug)]
88
pub struct EventHandler {

src/coll/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ use crate::{
3030

3131
/// `Collection` is the client-side abstraction of a MongoDB Collection. It can be used to
3232
/// perform collection-level operations such as CRUD operations. A `Collection` can be obtained
33-
/// through a `Database` by calling either `Database::collection` or
34-
/// `Database::collection_with_options`.
33+
/// through a [`Database`](struct.Database.html) by calling either
34+
/// [`Database::collection`](struct.Database.html#method.collection) or
35+
/// [`Database::collection_with_options`](struct.Database.html#method.collection_with_options).
3536
///
3637
/// `Collection` uses [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) internally,
3738
/// so it can safely be shared across threads. For example:
@@ -184,8 +185,8 @@ impl Collection {
184185

185186
/// Gets the number of documents matching `filter`.
186187
///
187-
/// Note that using `Collection::estimated_document_count` is recommended instead of this method
188-
/// is most cases.
188+
/// Note that using [`Collection::estimated_document_count`](#method.estimated_document_count)
189+
/// is recommended instead of this method is most cases.
189190
pub fn count_documents(
190191
&self,
191192
filter: impl Into<Option<Document>>,

src/coll/options.rs

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
selection_criteria::SelectionCriteria,
1313
};
1414

15-
/// These are the valid options for creating a `Collection` with
16-
/// `Database::collection_with_options`.
15+
/// These are the valid options for creating a [`Collection`](../struct.Collection.html) with
16+
/// [`Database::collection_with_options`](../struct.Database.html#method.collection_with_options).
1717
#[derive(Debug, Default, TypedBuilder)]
1818
pub struct CollectionOptions {
1919
/// The default read preference for operations.
@@ -29,7 +29,9 @@ pub struct CollectionOptions {
2929
pub write_concern: Option<WriteConcern>,
3030
}
3131

32-
/// Specifies whether a `Collection::find_one_and_replace` and `Collection::find_one_and_update`
32+
/// Specifies whether a
33+
/// [`Collection::find_one_and_replace`](../struct.Collection.html#method.find_one_and_replace) and
34+
/// [`Collection::find_one_and_update`](../struct.Collection.html#method.find_one_and_update)
3335
/// operation should return the document before or after modification.
3436
#[derive(Debug)]
3537
pub enum ReturnDocument {
@@ -73,7 +75,8 @@ pub enum CursorType {
7375
TailableAwait,
7476
}
7577

76-
/// Specifies the options to a `Collection::insert_one` operation.
78+
/// Specifies the options to a
79+
/// [`Collection::insert_one`](../struct.Collection.html#method.insert_one) operation.
7780
#[derive(Clone, Debug, Default, TypedBuilder)]
7881
pub struct InsertOneOptions {
7982
/// Opt out of document-level validation.
@@ -85,7 +88,8 @@ pub struct InsertOneOptions {
8588
pub write_concern: Option<WriteConcern>,
8689
}
8790

88-
/// Specifies the options to a `Collection::insert_many` operation.
91+
/// Specifies the options to a
92+
/// [`Collection::insert_many`](../struct.Collection.html#method.insert_many) operation.
8993
#[skip_serializing_none]
9094
#[derive(Clone, Debug, Default, TypedBuilder, Serialize, Deserialize)]
9195
#[serde(rename_all = "camelCase")]
@@ -154,7 +158,9 @@ impl From<Vec<Document>> for UpdateModifications {
154158
}
155159
}
156160

157-
/// Specifies the options to a `Collection::update_one` or `Collection::update_many` operation.
161+
/// Specifies the options to a
162+
/// [`Collection::update_one`](../struct.Collection.html#method.update_one) or
163+
/// [`Collection::update_many`](../struct.Collection.html#method.update_many) operation.
158164
#[derive(Debug, Default, TypedBuilder)]
159165
pub struct UpdateOptions {
160166
/// A set of filters specifying to which array elements an update should apply.
@@ -204,7 +210,8 @@ impl UpdateOptions {
204210
}
205211
}
206212

207-
/// Specifies the options to a `Collection::replace_one` operation.
213+
/// Specifies the options to a
214+
/// [`Collection::replace_one`](../struct.Collection.html#method.replace_one) operation.
208215
#[derive(Debug, Default, TypedBuilder)]
209216
pub struct ReplaceOptions {
210217
/// Opt out of document-level validation.
@@ -233,7 +240,9 @@ pub struct ReplaceOptions {
233240
pub write_concern: Option<WriteConcern>,
234241
}
235242

236-
/// Specifies the options to a `Collection::delete_one` or `Collection::delete_many` operation.
243+
/// Specifies the options to a
244+
/// [`Collection::delete_one`](../struct.Collection.html#method.delete_one) or
245+
/// [`Collection::delete_many`](../struct.Collection.html#method.delete_many) operation.
237246
#[serde_with::skip_serializing_none]
238247
#[derive(Debug, Default, TypedBuilder, Serialize)]
239248
#[serde(rename_all = "camelCase")]
@@ -250,7 +259,9 @@ pub struct DeleteOptions {
250259
pub write_concern: Option<WriteConcern>,
251260
}
252261

253-
/// Specifies the options to a `Collection::find_one_and_delete` operation.
262+
/// Specifies the options to a
263+
/// [`Collection::find_one_and_delete`](../struct.Collection.html#method.find_one_and_delete)
264+
/// operation.
254265
#[derive(Debug, Default, TypedBuilder)]
255266
pub struct FindOneAndDeleteOptions {
256267
/// The maximum amount of time to allow the query to run.
@@ -280,7 +291,9 @@ pub struct FindOneAndDeleteOptions {
280291
pub collation: Option<Collation>,
281292
}
282293

283-
/// Specifies the options to a `Collection::find_one_and_replace` operation.
294+
/// Specifies the options to a
295+
/// [`Collection::find_one_and_replace`](../struct.Collection.html#method.find_one_and_replace)
296+
/// operation.
284297
#[derive(Debug, Default, TypedBuilder)]
285298
pub struct FindOneAndReplaceOptions {
286299
/// Opt out of document-level validation.
@@ -322,13 +335,16 @@ pub struct FindOneAndReplaceOptions {
322335
pub collation: Option<Collation>,
323336
}
324337

325-
/// Specifies the options to a `Collection::find_one_and_update` operation.
338+
/// Specifies the options to a
339+
/// [`Collection::find_one_and_update`](../struct.Collection.html#method.find_one_and_update)
340+
/// operation.
326341
#[derive(Debug, Default, TypedBuilder)]
327342
pub struct FindOneAndUpdateOptions {
328343
/// A set of filters specifying to which array elements an update should apply.
329344
///
330345
/// See the documentation [here](https://docs.mongodb.com/manual/reference/command/update/) for
331-
/// more information on array filters.#[builder(default)]
346+
/// more information on array filters.
347+
#[builder(default)]
332348
pub array_filters: Option<Vec<Document>>,
333349

334350
/// Opt out of document-level validation.
@@ -370,7 +386,8 @@ pub struct FindOneAndUpdateOptions {
370386
pub collation: Option<Collation>,
371387
}
372388

373-
/// Specifies the options to a `Collection::aggregate` operation.
389+
/// Specifies the options to a [`Collection::aggregate`](../struct.Collection.html#method.aggregate)
390+
/// operation.
374391
#[skip_serializing_none]
375392
#[serde(rename_all = "camelCase")]
376393
#[derive(Clone, Debug, Default, TypedBuilder, Serialize)]
@@ -452,7 +469,8 @@ pub struct AggregateOptions {
452469
pub write_concern: Option<WriteConcern>,
453470
}
454471

455-
/// Specifies the options to a `Collection::count_documents` operation.
472+
/// Specifies the options to a
473+
/// [`Collection::count_documents`](../struct.Collection.html#method.count_documents) operation.
456474
#[derive(Debug, Default, TypedBuilder)]
457475
pub struct CountOptions {
458476
/// The index to use for the operation.
@@ -482,7 +500,13 @@ pub struct CountOptions {
482500
pub collation: Option<Collation>,
483501
}
484502

485-
/// Specifies the options to a `Collection::estimated_document_count` operation.
503+
// rustfmt tries to split the link up when it's all on one line, which breaks the link, so we wrap
504+
// the link contents in whitespace to get it to render correctly.
505+
//
506+
/// Specifies the options to a
507+
/// [
508+
/// `Collection::estimated_document_count`
509+
/// ](../struct.Collection.html#method.estimated_document_count) operation.
486510
#[serde_with::skip_serializing_none]
487511
#[derive(Debug, Default, TypedBuilder, Serialize, Clone)]
488512
#[serde(rename_all = "camelCase")]
@@ -498,16 +522,20 @@ pub struct EstimatedDocumentCountOptions {
498522
)]
499523
pub max_time: Option<Duration>,
500524

525+
/// The criteria used to select a server for this operation.
526+
///
527+
/// If none specified, the default set on the collection will be used.
501528
#[builder(default)]
502529
#[serde(skip_serializing)]
503530
pub selection_criteria: Option<SelectionCriteria>,
504531

505-
/// The level of the read concern
532+
/// The level of the read concern.
506533
#[builder(default)]
507534
pub read_concern: Option<ReadConcern>,
508535
}
509536

510-
/// Specifies the options to a `Collection::distinct` operation.
537+
/// Specifies the options to a [`Collection::distinct`](../struct.Collection.html#method.distinct)
538+
/// operation.
511539
#[serde_with::skip_serializing_none]
512540
#[derive(Debug, Default, TypedBuilder, Serialize, Clone)]
513541
#[serde(rename_all = "camelCase")]
@@ -523,11 +551,14 @@ pub struct DistinctOptions {
523551
)]
524552
pub max_time: Option<Duration>,
525553

554+
/// The criteria used to select a server for this operation.
555+
///
556+
/// If none specified, the default set on the collection will be used.
526557
#[builder(default)]
527558
#[serde(skip_serializing)]
528559
pub selection_criteria: Option<SelectionCriteria>,
529560

530-
/// The level of the read concern
561+
/// The level of the read concern.
531562
#[builder(default)]
532563
pub read_concern: Option<ReadConcern>,
533564

@@ -539,7 +570,8 @@ pub struct DistinctOptions {
539570
pub collation: Option<Collation>,
540571
}
541572

542-
/// Specifies the options to a `Collection::find` operation.
573+
/// Specifies the options to a [`Collection::find`](../struct.Collection.html#method.find)
574+
/// operation.
543575
#[skip_serializing_none]
544576
#[derive(Debug, Default, TypedBuilder, Serialize)]
545577
#[serde(rename_all = "camelCase")]
@@ -692,7 +724,8 @@ where
692724
}
693725
}
694726

695-
/// Specifies the options to a `Collection::find_one` operation.
727+
/// Specifies the options to a [`Collection::find_one`](../struct.Collection.html#method.find_one)
728+
/// operation.
696729
#[derive(Debug, Default, TypedBuilder)]
697730
pub struct FindOneOptions {
698731
/// If true, partial results will be returned from a mongos rather than an error being
@@ -771,7 +804,8 @@ pub struct IndexModel {
771804
pub options: Option<Document>,
772805
}
773806

774-
/// Specifies the options to a `Collection::drop` operation.
807+
/// Specifies the options to a [`Collection::drop`](../struct.Collection.html#method.drop)
808+
/// operation.
775809
#[derive(Debug, Default, TypedBuilder, Serialize)]
776810
#[serde(rename_all = "camelCase")]
777811
pub struct DropCollectionOptions {

src/concern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct WriteConcern {
9696
pub journal: Option<bool>,
9797
}
9898

99-
/// The type of the `w` field in a write concern.
99+
/// The type of the `w` field in a [`WriteConcern`](struct.WriteConcern.html).
100100
#[derive(Clone, Debug, PartialEq)]
101101
pub enum Acknowledgment {
102102
/// Requires acknowledgement that the write has reached the specified number of nodes.

0 commit comments

Comments
 (0)