Skip to content

Commit 6666a46

Browse files
authored
RUST-615 Upgrade typed-builder to 0.9.0 (#325)
1 parent 2f560a6 commit 6666a46

File tree

20 files changed

+179
-314
lines changed

20 files changed

+179
-314
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ take_mut = "0.2.2"
5555
thiserror = "1.0.24"
5656
trust-dns-proto = "0.20.0"
5757
trust-dns-resolver = "0.20.0"
58-
typed-builder = "0.4.0"
58+
typed-builder = "0.9.0"
5959
version_check = "0.9.1"
6060
webpki = "0.21.0"
6161
webpki-roots = "0.21.0"

src/client/auth/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,29 +325,25 @@ impl FromStr for AuthMechanism {
325325
/// Some fields (mechanism and source) may be omitted and will either be negotiated or assigned a
326326
/// default value, depending on the values of other fields in the credential.
327327
#[derive(Clone, Debug, Default, Deserialize, TypedBuilder, PartialEq)]
328+
#[builder(field_defaults(default, setter(strip_option)))]
328329
#[non_exhaustive]
329330
pub struct Credential {
330331
/// The username to authenticate with. This applies to all mechanisms but may be omitted when
331332
/// authenticating via MONGODB-X509.
332-
#[builder(default)]
333333
pub username: Option<String>,
334334

335335
/// The database used to authenticate. This applies to all mechanisms and defaults to "admin"
336336
/// in SCRAM authentication mechanisms and "$external" for GSSAPI, MONGODB-X509 and PLAIN.
337-
#[builder(default)]
338337
pub source: Option<String>,
339338

340339
/// The password to authenticate with. This does not apply to all mechanisms.
341-
#[builder(default)]
342340
pub password: Option<String>,
343341

344342
/// Which authentication mechanism to use. If not provided, one will be negotiated with the
345343
/// server.
346-
#[builder(default)]
347344
pub mechanism: Option<AuthMechanism>,
348345

349346
/// Additional properties for the given mechanism.
350-
#[builder(default)]
351347
pub mechanism_properties: Option<Document>,
352348
}
353349

src/client/options/mod.rs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ pub(crate) struct ServerApi {
258258

259259
/// Whether the MongoDB server should reject all commands that are not part of the
260260
/// declared API version. This includes command options and aggregation pipeline stages.
261-
#[builder(default)]
261+
#[builder(default, setter(strip_option))]
262262
pub strict: Option<bool>,
263263

264264
/// Whether the MongoDB server should return command failures when functionality that is
265265
/// deprecated from the declared API version is used.
266266
/// Note that at the time of this writing, no deprecations in version 1 exist.
267-
#[builder(default)]
267+
#[builder(default, setter(strip_option))]
268268
pub deprecation_errors: Option<bool>,
269269
}
270270

@@ -289,54 +289,54 @@ pub struct ClientOptions {
289289
/// The application name that the Client will send to the server as part of the handshake. This
290290
/// can be used in combination with the server logs to determine which Client is connected to a
291291
/// server.
292-
#[builder(default)]
292+
#[builder(default, setter(strip_option))]
293293
pub app_name: Option<String>,
294294

295-
#[builder(default)]
295+
#[builder(default, setter(skip))]
296296
pub(crate) compressors: Option<Vec<String>>,
297297

298298
/// The handler that should process all Connection Monitoring and Pooling events. See the
299299
/// CmapEventHandler type documentation for more details.
300300
#[derivative(Debug = "ignore", PartialEq = "ignore")]
301-
#[builder(default)]
301+
#[builder(default, setter(strip_option))]
302302
#[serde(skip)]
303303
pub cmap_event_handler: Option<Arc<dyn CmapEventHandler>>,
304304

305305
/// The handler that should process all command-related events. See the CommandEventHandler
306306
/// type documentation for more details.
307307
#[derivative(Debug = "ignore", PartialEq = "ignore")]
308-
#[builder(default)]
308+
#[builder(default, setter(strip_option))]
309309
#[serde(skip)]
310310
pub command_event_handler: Option<Arc<dyn CommandEventHandler>>,
311311

312312
/// The connect timeout passed to each underlying TcpStream when attemtping to connect to the
313313
/// server.
314314
///
315315
/// The default value is 10 seconds.
316-
#[builder(default)]
316+
#[builder(default, setter(strip_option))]
317317
pub connect_timeout: Option<Duration>,
318318

319319
/// The credential to use for authenticating connections made by this client.
320-
#[builder(default)]
320+
#[builder(default, setter(strip_option))]
321321
pub credential: Option<Credential>,
322322

323323
/// Specifies whether the Client should directly connect to a single host rather than
324324
/// autodiscover all servers in the cluster.
325325
///
326326
/// The default value is false.
327-
#[builder(default)]
327+
#[builder(default, setter(strip_option))]
328328
pub direct_connection: Option<bool>,
329329

330330
/// Extra information to append to the driver version in the metadata of the handshake with the
331331
/// server. This should be used by libraries wrapping the driver, e.g. ODMs.
332-
#[builder(default)]
332+
#[builder(default, setter(strip_option))]
333333
pub driver_info: Option<DriverInfo>,
334334

335335
/// The amount of time each monitoring thread should wait between sending an isMaster command
336336
/// to its respective server.
337337
///
338338
/// The default value is 10 seconds.
339-
#[builder(default)]
339+
#[builder(default, setter(strip_option))]
340340
pub heartbeat_freq: Option<Duration>,
341341

342342
/// When running a read operation with a ReadPreference that allows selecting secondaries,
@@ -350,14 +350,14 @@ pub struct ClientOptions {
350350
/// lowest average round trip time is eligible.
351351
///
352352
/// The default value is 15 ms.
353-
#[builder(default)]
353+
#[builder(default, setter(strip_option))]
354354
pub local_threshold: Option<Duration>,
355355

356356
/// The amount of time that a connection can remain idle in a connection pool before being
357357
/// closed. A value of zero indicates that connections should not be closed due to being idle.
358358
///
359359
/// By default, connections will not be closed due to being idle.
360-
#[builder(default)]
360+
#[builder(default, setter(strip_option))]
361361
pub max_idle_time: Option<Duration>,
362362

363363
/// The maximum amount of connections that the Client should allow to be created in a
@@ -366,41 +366,41 @@ pub struct ClientOptions {
366366
/// operation finishes and its connection is checked back into the pool.
367367
///
368368
/// The default value is 100.
369-
#[builder(default)]
369+
#[builder(default, setter(strip_option))]
370370
pub max_pool_size: Option<u32>,
371371

372372
/// The minimum number of connections that should be available in a server's connection pool at
373373
/// a given time. If fewer than `min_pool_size` connections are in the pool, connections will
374374
/// be added to the pool in the background until `min_pool_size` is reached.
375375
///
376376
/// The default value is 0.
377-
#[builder(default)]
377+
#[builder(default, setter(strip_option))]
378378
pub min_pool_size: Option<u32>,
379379

380380
/// Specifies the default read concern for operations performed on the Client. See the
381381
/// ReadConcern type documentation for more details.
382-
#[builder(default)]
382+
#[builder(default, setter(strip_option))]
383383
pub read_concern: Option<ReadConcern>,
384384

385385
/// The name of the replica set that the Client should connect to.
386-
#[builder(default)]
386+
#[builder(default, setter(strip_option))]
387387
pub repl_set_name: Option<String>,
388388

389389
/// Whether or not the client should retry a read operation if the operation fails.
390390
///
391391
/// The default value is true.
392-
#[builder(default)]
392+
#[builder(default, setter(strip_option))]
393393
pub retry_reads: Option<bool>,
394394

395395
/// Whether or not the client should retry a write operation if the operation fails.
396396
///
397397
/// The default value is true.
398-
#[builder(default)]
398+
#[builder(default, setter(strip_option))]
399399
pub retry_writes: Option<bool>,
400400

401401
/// The default selection criteria for operations performed on the Client. See the
402402
/// SelectionCriteria type documentation for more details.
403-
#[builder(default)]
403+
#[builder(default, setter(strip_option))]
404404
pub selection_criteria: Option<SelectionCriteria>,
405405

406406
/// The declared API version for this client.
@@ -412,58 +412,59 @@ pub struct ClientOptions {
412412
/// supported and is considered undefined behaviour. To run any command with a different API
413413
/// version or without declaring one, create a separate client that declares the
414414
/// appropriate API version.
415-
#[builder(default, skip)]
415+
#[builder(default, setter(skip))]
416416
pub(crate) server_api: Option<ServerApi>,
417417

418418
/// The amount of time the Client should attempt to select a server for an operation before
419419
/// timing outs
420420
///
421421
/// The default value is 30 seconds.
422-
#[builder(default)]
422+
#[builder(default, setter(strip_option))]
423423
pub server_selection_timeout: Option<Duration>,
424424

425-
#[builder(default)]
425+
#[builder(default, setter(skip))]
426426
pub(crate) socket_timeout: Option<Duration>,
427427

428428
/// The TLS configuration for the Client to use in its connections with the server.
429429
///
430430
/// By default, TLS is disabled.
431-
#[builder(default)]
431+
#[builder(default, setter(strip_option))]
432432
pub tls: Option<Tls>,
433433

434434
/// The amount of time a thread should block while waiting to check out a connection before
435435
/// returning an error. Note that if there are fewer than `max_pool_size` connections checked
436436
/// out or if a connection is available in the pool, checking out a connection will not block.
437437
///
438438
/// By default, threads will wait indefinitely for a connection to become available.
439-
#[builder(default)]
439+
#[builder(default, setter(strip_option))]
440440
pub wait_queue_timeout: Option<Duration>,
441441

442442
/// Specifies the default write concern for operations performed on the Client. See the
443443
/// WriteConcern type documentation for more details.
444-
#[builder(default)]
444+
#[builder(default, setter(strip_option))]
445445
pub write_concern: Option<WriteConcern>,
446446

447-
#[builder(default)]
447+
#[builder(default, setter(skip))]
448448
pub(crate) zlib_compression: Option<i32>,
449449

450-
#[builder(default)]
450+
#[builder(default, setter(skip))]
451451
pub(crate) original_srv_hostname: Option<String>,
452452

453-
#[builder(default)]
453+
#[builder(default, setter(skip))]
454454
pub(crate) original_uri: Option<String>,
455455

456456
/// Configuration of the trust-dns resolver used for SRV and TXT lookups.
457457
/// By default, the host system's resolver configuration will be used.
458458
///
459459
/// On Windows, there is a known performance issue in trust-dns with using the default system
460460
/// configuration, so a custom configuration is recommended.
461-
#[builder(default)]
461+
#[builder(default, setter(skip))]
462462
#[serde(skip)]
463463
pub(crate) resolver_config: Option<ResolverConfig>,
464464

465465
/// Used by tests to override MIN_HEARTBEAT_FREQUENCY.
466-
#[builder(default)]
466+
#[builder(default, setter(strip_option))]
467+
#[cfg(test)]
467468
pub(crate) heartbeat_freq_test: Option<Duration>,
468469
}
469470

@@ -540,27 +541,25 @@ impl From<TlsOptions> for Option<Tls> {
540541

541542
/// Specifies the TLS configuration that the [`Client`](../struct.Client.html) should use.
542543
#[derive(Clone, Debug, Default, Deserialize, PartialEq, TypedBuilder)]
544+
#[builder(field_defaults(default, setter(strip_option)))]
543545
#[non_exhaustive]
544546
pub struct TlsOptions {
545547
/// Whether or not the [`Client`](../struct.Client.html) should return an error if the server
546548
/// presents an invalid certificate. This setting should _not_ be set to `true` in
547549
/// production; it should only be used for testing.
548550
///
549551
/// The default value is to error when the server presents an invalid certificate.
550-
#[builder(default)]
551552
pub allow_invalid_certificates: Option<bool>,
552553

553554
/// The path to the CA file that the [`Client`](../struct.Client.html) should use for TLS. If
554555
/// none is specified, then the driver will use the Mozilla root certificates from the
555556
/// `webpki-roots` crate.
556-
#[builder(default)]
557557
pub ca_file_path: Option<String>,
558558

559559
/// The path to the certificate file that the [`Client`](../struct.Client.html) should present
560560
/// to the server to verify its identify. If none is specified, then the
561561
/// [`Client`](../struct.Client.html) will not attempt to verify its identity to the
562562
/// server.
563-
#[builder(default)]
564563
pub cert_key_file_path: Option<String>,
565564
}
566565

@@ -645,11 +644,11 @@ pub struct DriverInfo {
645644
pub name: String,
646645

647646
/// The version of the library wrapping the driver.
648-
#[builder(default)]
647+
#[builder(default, setter(strip_option))]
649648
pub version: Option<String>,
650649

651650
/// Optional platform information for the wrapping driver.
652-
#[builder(default)]
651+
#[builder(default, setter(strip_option))]
653652
pub platform: Option<String>,
654653
}
655654

@@ -684,8 +683,9 @@ impl From<ClientOptionsParser> for ClientOptions {
684683
original_srv_hostname: None,
685684
original_uri: Some(parser.original_uri),
686685
resolver_config: None,
687-
heartbeat_freq_test: None,
688686
server_api: None,
687+
#[cfg(test)]
688+
heartbeat_freq_test: None,
689689
}
690690
}
691691
}
@@ -2070,4 +2070,5 @@ mod tests {
20702070
/// Contains the options that can be used to create a new
20712071
/// [`ClientSession`](../struct.ClientSession.html).
20722072
#[derive(Clone, Debug, Deserialize, TypedBuilder)]
2073+
#[builder(field_defaults(default, setter(strip_option)))]
20732074
pub struct SessionOptions {}

src/client/session/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ async fn find_and_getmore_share_session() {
482482
async fn run_test(client: &EventClient, coll: &Collection, read_preference: ReadPreference) {
483483
let options = FindOptions::builder()
484484
.batch_size(2)
485-
.selection_criteria(Some(read_preference.into()))
485+
.selection_criteria(read_preference.into())
486486
.build();
487487

488488
let mut cursor = coll

src/cmap/establish/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ async fn speculative_auth_test(
3434
.await
3535
.unwrap();
3636

37-
let pool_options = ConnectionPoolOptions::builder()
37+
let mut pool_options = ConnectionPoolOptions::builder()
3838
.credential(credential.clone())
39-
.tls_options(CLIENT_OPTIONS.tls_options())
4039
.build();
40+
pool_options.tls_options = CLIENT_OPTIONS.tls_options();
4141

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

0 commit comments

Comments
 (0)