Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST-1695 Use consistent defaults for TypedBuilder #1072

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/change_stream/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,32 @@ use crate::{
/// [`ChangeStream`](crate::change_stream::ChangeStream).
#[skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, Serialize, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct ChangeStreamOptions {
#[rustfmt::skip]
/// Configures how the
/// [`ChangeStreamEvent::full_document`](crate::change_stream::event::ChangeStreamEvent::full_document)
/// field will be populated. By default, the field will be empty for updates.
#[builder(default)]
pub full_document: Option<FullDocumentType>,

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

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

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

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

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

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

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

/// Specifies a collation.
#[builder(default)]
#[serde(skip_serializing)]
pub collation: Option<Collation>,

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

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ pub struct CallbackContext {
}

#[derive(TypedBuilder)]
#[builder(field_defaults(setter(into)))]
#[builder(field_defaults(default, setter(into)))]
#[non_exhaustive]
pub struct IdpServerResponse {
#[builder(!default)]
pub access_token: String,
pub expires: Option<Instant>,
pub refresh_token: Option<String>,
Expand Down
55 changes: 14 additions & 41 deletions src/client/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,30 +334,29 @@ impl<'de> Deserialize<'de> for ServerApiVersion {
/// https://www.mongodb.com/docs/v5.0/reference/stable-api/) manual page.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, TypedBuilder)]
#[builder(field_defaults(setter(into)))]
#[builder(field_defaults(default, setter(into)))]
#[non_exhaustive]
pub struct ServerApi {
/// The declared API version.
#[serde(rename = "apiVersion")]
#[builder(!default)]
pub version: ServerApiVersion,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/// Default database for this client.
///
/// By default, no default database is specified.
#[builder(default)]
pub default_database: Option<String>,

#[builder(default, setter(skip))]
#[builder(setter(skip))]
#[derivative(Debug = "ignore")]
pub(crate) socket_timeout: Option<Duration>,

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

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

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

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

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

#[cfg(test)]
#[builder(default, setter(skip))]
#[builder(setter(skip))]
#[derivative(Debug = "ignore")]
pub(crate) original_uri: Option<String>,

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

/// Control test behavior of the client.
#[cfg(test)]
#[builder(default, setter(skip))]
#[builder(setter(skip))]
#[serde(skip)]
#[derivative(PartialEq = "ignore")]
pub(crate) test_options: Option<TestOptions>,
Expand Down Expand Up @@ -1061,18 +1035,17 @@ impl TlsOptions {
/// Extra information to append to the driver version in the metadata of the handshake with the
/// server. This should be used by libraries wrapping the driver, e.g. ODMs.
#[derive(Clone, Debug, Deserialize, TypedBuilder, PartialEq)]
#[builder(field_defaults(setter(into)))]
#[builder(field_defaults(default, setter(into)))]
#[non_exhaustive]
pub struct DriverInfo {
/// The name of the library wrapping the driver.
#[builder(!default)]
pub name: String,

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

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

Expand Down
Loading