Skip to content

Commit cdbae2d

Browse files
authored
RUST-732 Mark the versioned API options public. (#401)
1 parent 6d5a3d4 commit cdbae2d

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

src/client/options/mod.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ impl fmt::Display for ServerAddress {
294294
/// Specifies the server API version to declare
295295
#[derive(Clone, Debug, PartialEq)]
296296
#[non_exhaustive]
297-
pub(crate) enum ServerApiVersion {
297+
pub enum ServerApiVersion {
298+
/// Use API version 1.
298299
V1,
299300
}
300301

@@ -332,12 +333,13 @@ impl<'de> Deserialize<'de> for ServerApiVersion {
332333
}
333334
}
334335

335-
/// Options used to declare a versioned server API.
336+
/// Options used to declare a versioned server API. For more information, see the [Versioned API](
337+
/// https://docs.mongodb.com/v5.0/reference/versioned-api/) manual page.
336338
#[derive(Clone, Debug, Deserialize, PartialEq, TypedBuilder)]
337339
#[builder(field_defaults(setter(into)))]
338340
#[serde(rename_all = "camelCase")]
339341
#[non_exhaustive]
340-
pub(crate) struct ServerApi {
342+
pub struct ServerApi {
341343
/// The declared API version.
342344
pub version: ServerApiVersion,
343345

@@ -493,15 +495,17 @@ pub struct ClientOptions {
493495

494496
/// The declared API version for this client.
495497
/// The declared API version is applied to all commands run through the client, including those
496-
/// sent through any [crate::Database] or [crate::Collection] derived from the client.
498+
/// sent through any handle derived from the client.
497499
///
498-
/// Specifying versioned API options in the command document passed to
499-
/// [crate::Database::run_command] AND declaring an API version on the client is not
500-
/// supported and is considered undefined behaviour. To run any command with a different API
501-
/// version or without declaring one, create a separate client that declares the
502-
/// appropriate API version.
503-
#[builder(default, setter(skip))]
504-
pub(crate) server_api: Option<ServerApi>,
500+
/// Specifying versioned API options in the command document passed to `run_command` AND
501+
/// declaring an API version on the client is not supported and is considered undefined
502+
/// behaviour. To run any command with a different API version or without declaring one, create
503+
/// a separate client that declares the appropriate API version.
504+
///
505+
/// For more information, see the [Versioned API](
506+
/// https://docs.mongodb.com/v5.0/reference/versioned-api/) manual page.
507+
#[builder(default)]
508+
pub server_api: Option<ServerApi>,
505509

506510
/// The amount of time the Client should attempt to select a server for an operation before
507511
/// timing outs

src/cmap/establish/handshake/test.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use super::Handshaker;
2-
use crate::{bson::doc, cmap::options::ConnectionPoolOptions, options::DriverInfo};
2+
use crate::{
3+
bson::doc,
4+
cmap::options::ConnectionPoolOptions,
5+
options::{ClientOptions, DriverInfo},
6+
};
37

48
#[test]
59
fn metadata_no_options() {
@@ -24,15 +28,17 @@ fn metadata_with_options() {
2428
let name = "even better Rust driver";
2529
let version = "the best version, of course";
2630

27-
let options = ConnectionPoolOptions::builder()
28-
.app_name(app_name.to_string())
29-
.driver_info(
30-
DriverInfo::builder()
31-
.name(name.to_string())
32-
.version(version.to_string())
33-
.build(),
34-
)
35-
.build();
31+
let options = ConnectionPoolOptions::from_client_options(
32+
&ClientOptions::builder()
33+
.app_name(app_name.to_string())
34+
.driver_info(
35+
DriverInfo::builder()
36+
.name(name.to_string())
37+
.version(version.to_string())
38+
.build(),
39+
)
40+
.build(),
41+
);
3642

3743
let handshaker = Handshaker::new(Some(options.into()));
3844

src/cmap/establish/test.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use tokio::sync::RwLockWriteGuard;
33
use crate::{
44
bson::{doc, Bson},
55
cmap::{establish::Handshaker, Command, Connection, ConnectionPoolOptions},
6-
options::{AuthMechanism, Credential, ReadPreference},
6+
options::{AuthMechanism, ClientOptions, Credential, ReadPreference},
77
test::{TestClient, CLIENT_OPTIONS, LOCK},
88
};
99

@@ -34,9 +34,11 @@ async fn speculative_auth_test(
3434
.await
3535
.unwrap();
3636

37-
let mut pool_options = ConnectionPoolOptions::builder()
38-
.credential(credential.clone())
39-
.build();
37+
let mut pool_options = ConnectionPoolOptions::from_client_options(
38+
&ClientOptions::builder()
39+
.credential(credential.clone())
40+
.build(),
41+
);
4042
pool_options.tls_options = CLIENT_OPTIONS.tls_options();
4143

4244
let handshaker = Handshaker::new(Some(pool_options.clone().into()));

src/cmap/options.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use crate::{
1616
};
1717

1818
/// Contains the options for creating a connection pool.
19-
#[derive(Clone, Default, Deserialize, TypedBuilder, Derivative)]
19+
#[derive(Clone, Default, Deserialize, Derivative)]
2020
#[derivative(Debug, PartialEq)]
21-
#[builder(field_defaults(default, setter(into)))]
2221
#[serde(rename_all = "camelCase")]
2322
pub(crate) struct ConnectionPoolOptions {
2423
/// The application name specified by the user. This is sent to the server as part of the
@@ -74,13 +73,11 @@ pub(crate) struct ConnectionPoolOptions {
7473
/// Whether to start the pool as "ready" or not.
7574
/// For tests only.
7675
#[cfg(test)]
77-
#[builder(setter(skip), default)]
7876
pub(crate) ready: Option<bool>,
7977

8078
/// The declared API version
8179
///
8280
/// The default value is to have no declared API version
83-
#[builder(setter(skip), default)]
8481
pub(crate) server_api: Option<ServerApi>,
8582

8683
/// The options specifying how a TLS connection should be configured. If `tls_options` is

src/test/spec/unified_runner/test_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub struct Client {
140140
pub observe_events: Option<Vec<String>>,
141141
pub ignore_command_monitoring_events: Option<Vec<String>>,
142142
#[serde(default)]
143-
pub(crate) server_api: Option<ServerApi>,
143+
pub server_api: Option<ServerApi>,
144144
}
145145

146146
fn default_uri() -> String {

0 commit comments

Comments
 (0)