Skip to content

Commit 131d53a

Browse files
authored
RUST-1695 Use consistent defaults for TypedBuilder (#1072)
1 parent a05f150 commit 131d53a

File tree

10 files changed

+44
-110
lines changed

10 files changed

+44
-110
lines changed

src/change_stream/options.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,32 @@ use crate::{
1717
/// [`ChangeStream`](crate::change_stream::ChangeStream).
1818
#[skip_serializing_none]
1919
#[derive(Clone, Debug, Default, Deserialize, Serialize, TypedBuilder)]
20+
#[builder(field_defaults(default, setter(into)))]
2021
#[serde(rename_all = "camelCase")]
2122
#[non_exhaustive]
2223
pub struct ChangeStreamOptions {
2324
#[rustfmt::skip]
2425
/// Configures how the
2526
/// [`ChangeStreamEvent::full_document`](crate::change_stream::event::ChangeStreamEvent::full_document)
2627
/// field will be populated. By default, the field will be empty for updates.
27-
#[builder(default)]
2828
pub full_document: Option<FullDocumentType>,
2929

3030
/// Configures how the
3131
/// [`ChangeStreamEvent::full_document_before_change`](
3232
/// crate::change_stream::event::ChangeStreamEvent::full_document_before_change) field will be
3333
/// populated. By default, the field will be empty for updates.
34-
#[builder(default)]
3534
pub full_document_before_change: Option<FullDocumentBeforeChangeType>,
3635

3736
/// Specifies the logical starting point for the new change stream. Note that if a watched
3837
/// collection is dropped and recreated or newly renamed, `start_after` should be set instead.
3938
/// `resume_after` and `start_after` cannot be set simultaneously.
4039
///
4140
/// For more information on resuming a change stream see the documentation [here](https://www.mongodb.com/docs/manual/changeStreams/#change-stream-resume-after)
42-
#[builder(default)]
4341
pub resume_after: Option<ResumeToken>,
4442

4543
/// The change stream will only provide changes that occurred at or after the specified
4644
/// timestamp. Any command run against the server will return an operation time that can be
4745
/// used here.
48-
#[builder(default)]
4946
pub start_at_operation_time: Option<Timestamp>,
5047

5148
/// Takes a resume token and starts a new change stream returning the first notification after
@@ -56,42 +53,36 @@ pub struct ChangeStreamOptions {
5653
///
5754
/// See the documentation [here](https://www.mongodb.com/docs/master/changeStreams/#change-stream-start-after) for more
5855
/// information.
59-
#[builder(default)]
6056
pub start_after: Option<ResumeToken>,
6157

6258
/// If `true`, the change stream will monitor all changes for the given cluster.
63-
#[builder(default, setter(skip))]
59+
#[builder(setter(skip))]
6460
pub(crate) all_changes_for_cluster: Option<bool>,
6561

6662
/// The maximum amount of time for the server to wait on new documents to satisfy a change
6763
/// stream query.
68-
#[builder(default)]
6964
#[serde(skip_serializing)]
7065
pub max_await_time: Option<Duration>,
7166

7267
/// The number of documents to return per batch.
73-
#[builder(default)]
7468
#[serde(skip_serializing)]
7569
pub batch_size: Option<u32>,
7670

7771
/// Specifies a collation.
78-
#[builder(default)]
7972
#[serde(skip_serializing)]
8073
pub collation: Option<Collation>,
8174

8275
/// The read concern to use for the operation.
8376
///
8477
/// If none is specified, the read concern defined on the object executing this operation will
8578
/// be used.
86-
#[builder(default)]
8779
#[serde(skip_serializing)]
8880
pub read_concern: Option<ReadConcern>,
8981

9082
/// The criteria used to select a server for this operation.
9183
///
9284
/// If none is specified, the selection criteria defined on the object executing this operation
9385
/// will be used.
94-
#[builder(default)]
9586
#[serde(skip_serializing)]
9687
pub selection_criteria: Option<SelectionCriteria>,
9788

@@ -100,7 +91,6 @@ pub struct ChangeStreamOptions {
10091
///
10192
/// The comment can be any [`Bson`] value on server versions 4.4+. On lower server versions,
10293
/// the comment must be a [`Bson::String`] value.
103-
#[builder(default)]
10494
pub comment: Option<Bson>,
10595
}
10696

src/client/auth/oidc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ pub struct CallbackContext {
160160
}
161161

162162
#[derive(TypedBuilder)]
163-
#[builder(field_defaults(setter(into)))]
163+
#[builder(field_defaults(default, setter(into)))]
164164
#[non_exhaustive]
165165
pub struct IdpServerResponse {
166+
#[builder(!default)]
166167
pub access_token: String,
167168
pub expires: Option<Instant>,
168169
pub refresh_token: Option<String>,

src/client/options.rs

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -334,30 +334,29 @@ impl<'de> Deserialize<'de> for ServerApiVersion {
334334
/// https://www.mongodb.com/docs/v5.0/reference/stable-api/) manual page.
335335
#[serde_with::skip_serializing_none]
336336
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, TypedBuilder)]
337-
#[builder(field_defaults(setter(into)))]
337+
#[builder(field_defaults(default, setter(into)))]
338338
#[non_exhaustive]
339339
pub struct ServerApi {
340340
/// The declared API version.
341341
#[serde(rename = "apiVersion")]
342+
#[builder(!default)]
342343
pub version: ServerApiVersion,
343344

344345
/// Whether the MongoDB server should reject all commands that are not part of the
345346
/// declared API version. This includes command options and aggregation pipeline stages.
346-
#[builder(default)]
347347
#[serde(rename = "apiStrict")]
348348
pub strict: Option<bool>,
349349

350350
/// Whether the MongoDB server should return command failures when functionality that is
351351
/// deprecated from the declared API version is used.
352352
/// Note that at the time of this writing, no deprecations in version 1 exist.
353-
#[builder(default)]
354353
#[serde(rename = "apiDeprecationErrors")]
355354
pub deprecation_errors: Option<bool>,
356355
}
357356

358357
/// Contains the options that can be used to create a new [`Client`](../struct.Client.html).
359358
#[derive(Clone, Derivative, Deserialize, TypedBuilder)]
360-
#[builder(field_defaults(setter(into)))]
359+
#[builder(field_defaults(default, setter(into)))]
361360
#[derivative(Debug, PartialEq)]
362361
#[serde(rename_all = "camelCase")]
363362
#[non_exhaustive]
@@ -377,7 +376,6 @@ pub struct ClientOptions {
377376
/// The application name that the Client will send to the server as part of the handshake. This
378377
/// can be used in combination with the server logs to determine which Client is connected to a
379378
/// server.
380-
#[builder(default)]
381379
pub app_name: Option<String>,
382380

383381
/// The allowed compressors to use to compress messages sent to and decompress messages
@@ -389,55 +387,49 @@ pub struct ClientOptions {
389387
feature = "zlib-compression",
390388
feature = "snappy-compression"
391389
))]
392-
#[builder(default)]
393390
#[serde(skip)]
394391
pub compressors: Option<Vec<Compressor>>,
395392

396393
/// The handler that should process all Connection Monitoring and Pooling events.
397394
#[derivative(Debug = "ignore", PartialEq = "ignore")]
398-
#[builder(default, setter(strip_option))]
395+
#[builder(setter(strip_option))]
399396
#[serde(skip)]
400397
pub cmap_event_handler: Option<EventHandler<crate::event::cmap::CmapEvent>>,
401398

402399
/// The handler that should process all command-related events.
403400
///
404401
/// Note that monitoring command events may incur a performance penalty.
405402
#[derivative(Debug = "ignore", PartialEq = "ignore")]
406-
#[builder(default, setter(strip_option))]
403+
#[builder(setter(strip_option))]
407404
#[serde(skip)]
408405
pub command_event_handler: Option<EventHandler<crate::event::command::CommandEvent>>,
409406

410407
/// The connect timeout passed to each underlying TcpStream when attemtping to connect to the
411408
/// server.
412409
///
413410
/// The default value is 10 seconds.
414-
#[builder(default)]
415411
pub connect_timeout: Option<Duration>,
416412

417413
/// The credential to use for authenticating connections made by this client.
418-
#[builder(default)]
419414
pub credential: Option<Credential>,
420415

421416
/// Specifies whether the Client should directly connect to a single host rather than
422417
/// autodiscover all servers in the cluster.
423418
///
424419
/// The default value is false.
425-
#[builder(default)]
426420
pub direct_connection: Option<bool>,
427421

428422
/// Extra information to append to the driver version in the metadata of the handshake with the
429423
/// server. This should be used by libraries wrapping the driver, e.g. ODMs.
430-
#[builder(default)]
431424
pub driver_info: Option<DriverInfo>,
432425

433426
/// The amount of time each monitoring thread should wait between performing server checks.
434427
///
435428
/// The default value is 10 seconds.
436-
#[builder(default)]
437429
pub heartbeat_freq: Option<Duration>,
438430

439431
/// Whether or not the client is connecting to a MongoDB cluster through a load balancer.
440-
#[builder(default, setter(skip))]
432+
#[builder(setter(skip))]
441433
#[serde(rename = "loadbalanced")]
442434
pub load_balanced: Option<bool>,
443435

@@ -452,14 +444,12 @@ pub struct ClientOptions {
452444
/// lowest average round trip time is eligible.
453445
///
454446
/// The default value is 15 ms.
455-
#[builder(default)]
456447
pub local_threshold: Option<Duration>,
457448

458449
/// The amount of time that a connection can remain idle in a connection pool before being
459450
/// closed. A value of zero indicates that connections should not be closed due to being idle.
460451
///
461452
/// By default, connections will not be closed due to being idle.
462-
#[builder(default)]
463453
pub max_idle_time: Option<Duration>,
464454

465455
/// The maximum amount of connections that the Client should allow to be created in a
@@ -468,59 +458,50 @@ pub struct ClientOptions {
468458
/// operation finishes and its connection is checked back into the pool.
469459
///
470460
/// The default value is 10.
471-
#[builder(default)]
472461
pub max_pool_size: Option<u32>,
473462

474463
/// The minimum number of connections that should be available in a server's connection pool at
475464
/// a given time. If fewer than `min_pool_size` connections are in the pool, connections will
476465
/// be added to the pool in the background until `min_pool_size` is reached.
477466
///
478467
/// The default value is 0.
479-
#[builder(default)]
480468
pub min_pool_size: Option<u32>,
481469

482470
/// The maximum number of new connections that can be created concurrently.
483471
///
484472
/// If specified, this value must be greater than 0. The default is 2.
485-
#[builder(default)]
486473
pub max_connecting: Option<u32>,
487474

488475
/// Specifies the default read concern for operations performed on the Client. See the
489476
/// ReadConcern type documentation for more details.
490-
#[builder(default)]
491477
pub read_concern: Option<ReadConcern>,
492478

493479
/// The name of the replica set that the Client should connect to.
494-
#[builder(default)]
495480
pub repl_set_name: Option<String>,
496481

497482
/// Whether or not the client should retry a read operation if the operation fails.
498483
///
499484
/// The default value is true.
500-
#[builder(default)]
501485
pub retry_reads: Option<bool>,
502486

503487
/// Whether or not the client should retry a write operation if the operation fails.
504488
///
505489
/// The default value is true.
506-
#[builder(default)]
507490
pub retry_writes: Option<bool>,
508491

509492
/// Configures which server monitoring protocol to use.
510493
///
511494
/// The default is [`Auto`](ServerMonitoringMode::Auto).
512-
#[builder(default)]
513495
pub server_monitoring_mode: Option<ServerMonitoringMode>,
514496

515497
/// The handler that should process all Server Discovery and Monitoring events.
516498
#[derivative(Debug = "ignore", PartialEq = "ignore")]
517-
#[builder(default, setter(strip_option))]
499+
#[builder(setter(strip_option))]
518500
#[serde(skip)]
519501
pub sdam_event_handler: Option<EventHandler<crate::event::sdam::SdamEvent>>,
520502

521503
/// The default selection criteria for operations performed on the Client. See the
522504
/// SelectionCriteria type documentation for more details.
523-
#[builder(default)]
524505
pub selection_criteria: Option<SelectionCriteria>,
525506

526507
/// The declared API version for this client.
@@ -534,30 +515,26 @@ pub struct ClientOptions {
534515
///
535516
/// For more information, see the [Stable API](
536517
/// https://www.mongodb.com/docs/v5.0/reference/stable-api/) manual page.
537-
#[builder(default)]
538518
pub server_api: Option<ServerApi>,
539519

540520
/// The amount of time the Client should attempt to select a server for an operation before
541521
/// timing outs
542522
///
543523
/// The default value is 30 seconds.
544-
#[builder(default)]
545524
pub server_selection_timeout: Option<Duration>,
546525

547526
/// Default database for this client.
548527
///
549528
/// By default, no default database is specified.
550-
#[builder(default)]
551529
pub default_database: Option<String>,
552530

553-
#[builder(default, setter(skip))]
531+
#[builder(setter(skip))]
554532
#[derivative(Debug = "ignore")]
555533
pub(crate) socket_timeout: Option<Duration>,
556534

557535
/// The TLS configuration for the Client to use in its connections with the server.
558536
///
559537
/// By default, TLS is disabled.
560-
#[builder(default)]
561538
pub tls: Option<Tls>,
562539

563540
/// The maximum number of bytes that the driver should include in a tracing event
@@ -570,26 +547,23 @@ pub struct ClientOptions {
570547
///
571548
/// The default value is 1000.
572549
#[cfg(feature = "tracing-unstable")]
573-
#[builder(default)]
574550
pub tracing_max_document_length_bytes: Option<usize>,
575551

576552
/// Specifies the default write concern for operations performed on the Client. See the
577553
/// WriteConcern type documentation for more details.
578-
#[builder(default)]
579554
pub write_concern: Option<WriteConcern>,
580555

581556
/// Limit on the number of mongos connections that may be created for sharded topologies.
582-
#[builder(default)]
583557
pub srv_max_hosts: Option<u32>,
584558

585559
/// Information from the SRV URI that generated these client options, if applicable.
586-
#[builder(default, setter(skip))]
560+
#[builder(setter(skip))]
587561
#[serde(skip)]
588562
#[derivative(Debug = "ignore")]
589563
pub(crate) original_srv_info: Option<OriginalSrvInfo>,
590564

591565
#[cfg(test)]
592-
#[builder(default, setter(skip))]
566+
#[builder(setter(skip))]
593567
#[derivative(Debug = "ignore")]
594568
pub(crate) original_uri: Option<String>,
595569

@@ -598,15 +572,15 @@ pub struct ClientOptions {
598572
///
599573
/// On Windows, there is a known performance issue in trust-dns with using the default system
600574
/// configuration, so a custom configuration is recommended.
601-
#[builder(default, setter(skip))]
575+
#[builder(setter(skip))]
602576
#[serde(skip)]
603577
#[derivative(Debug = "ignore")]
604578
#[cfg(feature = "dns-resolver")]
605579
pub(crate) resolver_config: Option<ResolverConfig>,
606580

607581
/// Control test behavior of the client.
608582
#[cfg(test)]
609-
#[builder(default, setter(skip))]
583+
#[builder(setter(skip))]
610584
#[serde(skip)]
611585
#[derivative(PartialEq = "ignore")]
612586
pub(crate) test_options: Option<TestOptions>,
@@ -1061,18 +1035,17 @@ impl TlsOptions {
10611035
/// Extra information to append to the driver version in the metadata of the handshake with the
10621036
/// server. This should be used by libraries wrapping the driver, e.g. ODMs.
10631037
#[derive(Clone, Debug, Deserialize, TypedBuilder, PartialEq)]
1064-
#[builder(field_defaults(setter(into)))]
1038+
#[builder(field_defaults(default, setter(into)))]
10651039
#[non_exhaustive]
10661040
pub struct DriverInfo {
10671041
/// The name of the library wrapping the driver.
1042+
#[builder(!default)]
10681043
pub name: String,
10691044

10701045
/// The version of the library wrapping the driver.
1071-
#[builder(default)]
10721046
pub version: Option<String>,
10731047

10741048
/// Optional platform information for the wrapping driver.
1075-
#[builder(default)]
10761049
pub platform: Option<String>,
10771050
}
10781051

0 commit comments

Comments
 (0)