From 599beff31f0b95956071dbf6698881e1b2af0890 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Thu, 9 Jan 2025 14:57:29 +0800 Subject: [PATCH 1/2] chore: bump `derive_more`, `thiserror`, `typed-builder` --- Cargo.toml | 11 +++++++---- src/event/sdam/topology_description.rs | 2 +- src/selection_criteria.rs | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 85457e1cb..b0000842a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ chrono = { version = "0.4.7", default-features = false, features = [ "clock", "std", ] } -derive_more = "0.99.17" +derive_more = { version = "1.0", features = ["from", "display"] } derive-where = "1.2.7" flate2 = { version = "1.0", optional = true } futures-io = "0.3.21" @@ -98,7 +98,10 @@ openssl = { version = "0.10.38", optional = true } openssl-probe = { version = "0.1.5", optional = true } pem = { version = "3.0.4", optional = true } percent-encoding = "2.0.0" -pkcs8 = { version = "0.10.2", features = ["encryption", "pkcs5"], optional = true } +pkcs8 = { version = "0.10.2", features = [ + "encryption", + "pkcs5", +], optional = true } rand = { version = "0.8.3", features = ["small_rng"] } rayon = { version = "1.5.3", optional = true } rustc_version_runtime = "0.3.0" @@ -111,10 +114,10 @@ socket2 = "0.5.5" stringprep = "0.1.2" strsim = "0.11.1" take_mut = "0.2.2" -thiserror = "1.0.24" +thiserror = "2.0" tokio-openssl = { version = "0.6.3", optional = true } tracing = { version = "0.1.36", optional = true } -typed-builder = "0.10.0" +typed-builder = "0.20" webpki-roots = "0.25.2" zstd = { version = "0.11.2", optional = true } macro_magic = "0.5.1" diff --git a/src/event/sdam/topology_description.rs b/src/event/sdam/topology_description.rs index cc21cf068..a9e6e5bb7 100644 --- a/src/event/sdam/topology_description.rs +++ b/src/event/sdam/topology_description.rs @@ -12,7 +12,7 @@ use crate::{ /// A description of the most up-to-date information known about a topology. Further details can /// be found in the [Server Discovery and Monitoring specification](https://specifications.readthedocs.io/en/latest/server-discovery-and-monitoring/server-discovery-and-monitoring/). #[derive(Clone, derive_more::Display)] -#[display(fmt = "{}", description)] +#[display("{}", description)] pub struct TopologyDescription { pub(crate) description: crate::sdam::TopologyDescription, } diff --git a/src/selection_criteria.rs b/src/selection_criteria.rs index 4fce8125c..2460dc00e 100644 --- a/src/selection_criteria.rs +++ b/src/selection_criteria.rs @@ -21,12 +21,12 @@ pub enum SelectionCriteria { /// staleness, and server tags. /// /// See the documentation [here](https://www.mongodb.com/docs/manual/core/read-preference/) for more details. - #[display(fmt = "ReadPreference {}", _0)] + #[display("ReadPreference {}", _0)] ReadPreference(ReadPreference), /// A predicate used to filter servers that are considered suitable. A `server` will be /// considered suitable by a `predicate` if `predicate(server)` returns true. - #[display(fmt = "Custom predicate")] + #[display("Custom predicate")] Predicate(#[derive_where(skip)] Predicate), } From a90dd79eb50ba8aab00d321df22c40a336b9babb Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Thu, 27 Feb 2025 10:22:59 +0800 Subject: [PATCH 2/2] clippy --- src/action/find_and_modify.rs | 4 ++-- src/client/action/perf.rs | 2 +- src/client/auth/oidc.rs | 6 +----- src/client/session/action.rs | 2 +- src/cmap/conn/stream_description.rs | 2 +- src/cmap/establish/handshake.rs | 4 ++-- src/operation/aggregate/change_stream.rs | 4 ++-- src/operation/create_indexes.rs | 2 +- src/sdam/srv_polling.rs | 5 +---- 9 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/action/find_and_modify.rs b/src/action/find_and_modify.rs index 0fec48c0c..c21a9cee1 100644 --- a/src/action/find_and_modify.rs +++ b/src/action/find_and_modify.rs @@ -27,12 +27,12 @@ use crate::{ use super::{action_impl, deeplink, export_doc, option_setters, options_doc}; impl Collection { - async fn find_and_modify<'a>( + async fn find_and_modify( &self, filter: Document, modification: Modification, mut options: Option, - session: Option<&'a mut ClientSession>, + session: Option<&mut ClientSession>, ) -> Result> { resolve_write_concern_with_session!(self, options, session.as_ref())?; diff --git a/src/client/action/perf.rs b/src/client/action/perf.rs index 725080c1f..9555fc793 100644 --- a/src/client/action/perf.rs +++ b/src/client/action/perf.rs @@ -10,7 +10,7 @@ impl<'a> Action for crate::action::WarmConnectionPool<'a> { .inner .options .min_pool_size - .map_or(false, |s| s > 0) + .is_some_and(|s| s > 0) { // No-op when min_pool_size is zero. return; diff --git a/src/client/auth/oidc.rs b/src/client/auth/oidc.rs index b481ccb37..58b68137b 100644 --- a/src/client/auth/oidc.rs +++ b/src/client/auth/oidc.rs @@ -965,11 +965,7 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> { } } } - if credential - .source - .as_ref() - .map_or(false, |s| s != "$external") - { + if credential.source.as_ref().is_some_and(|s| s != "$external") { return Err(Error::invalid_argument(format!( "source must be $external for {} authentication, found: {:?}", MONGODB_OIDC_STR, credential.source diff --git a/src/client/session/action.rs b/src/client/session/action.rs index fccaabbae..7be9a1047 100644 --- a/src/client/session/action.rs +++ b/src/client/session/action.rs @@ -99,7 +99,7 @@ impl<'a> Action for StartTransaction<&'a mut ClientSession> { } } -impl<'a> StartTransaction<&'a mut ClientSession> { +impl StartTransaction<&mut ClientSession> { /// Starts a transaction, runs the given callback, and commits or aborts the transaction. /// Transient transaction errors will cause the callback or the commit to be retried; /// other errors will cause the transaction to be aborted and the error returned to the diff --git a/src/cmap/conn/stream_description.rs b/src/cmap/conn/stream_description.rs index 405806ab9..a12a7f2f6 100644 --- a/src/cmap/conn/stream_description.rs +++ b/src/cmap/conn/stream_description.rs @@ -76,6 +76,6 @@ impl StreamDescription { pub(crate) fn supports_retryable_writes(&self) -> bool { self.initial_server_type != ServerType::Standalone && self.logical_session_timeout.is_some() - && self.max_wire_version.map_or(false, |version| version >= 6) + && self.max_wire_version.is_some_and(|version| version >= 6) } } diff --git a/src/cmap/establish/handshake.rs b/src/cmap/establish/handshake.rs index c9b75a538..15b0acb2f 100644 --- a/src/cmap/establish/handshake.rs +++ b/src/cmap/establish/handshake.rs @@ -217,7 +217,7 @@ impl RuntimeEnvironment { } fn var_set(name: &str) -> bool { - env::var_os(name).map_or(false, |v| !v.is_empty()) + env::var_os(name).is_some_and(|v| !v.is_empty()) } impl FaasEnvironmentName { @@ -225,7 +225,7 @@ impl FaasEnvironmentName { use FaasEnvironmentName::*; let mut found: Option = None; let lambda_env = env::var_os("AWS_EXECUTION_ENV") - .map_or(false, |v| v.to_string_lossy().starts_with("AWS_Lambda_")); + .is_some_and(|v| v.to_string_lossy().starts_with("AWS_Lambda_")); if lambda_env || var_set("AWS_LAMBDA_RUNTIME_API") { found = Some(AwsLambda); } diff --git a/src/operation/aggregate/change_stream.rs b/src/operation/aggregate/change_stream.rs index e77f72a7e..00d56e56d 100644 --- a/src/operation/aggregate/change_stream.rs +++ b/src/operation/aggregate/change_stream.rs @@ -61,7 +61,7 @@ impl OperationWithDefaults for ChangeStreamAggregate { .start_at_operation_time .as_ref() .or(data.initial_operation_time.as_ref()); - if saved_time.is_some() && description.max_wire_version.map_or(false, |v| v >= 7) { + if saved_time.is_some() && description.max_wire_version.is_some_and(|v| v >= 7) { new_opts.start_at_operation_time = saved_time.cloned(); } } @@ -109,7 +109,7 @@ impl OperationWithDefaults for ChangeStreamAggregate { let description = context.connection.stream_description()?; if self.args.options.as_ref().map_or(true, has_no_time) - && description.max_wire_version.map_or(false, |v| v >= 7) + && description.max_wire_version.is_some_and(|v| v >= 7) && spec.initial_buffer.is_empty() && spec.post_batch_resume_token.is_none() { diff --git a/src/operation/create_indexes.rs b/src/operation/create_indexes.rs index 5bae53b57..8441933ba 100644 --- a/src/operation/create_indexes.rs +++ b/src/operation/create_indexes.rs @@ -48,7 +48,7 @@ impl OperationWithDefaults for CreateIndexes { && self .options .as_ref() - .map_or(false, |options| options.commit_quorum.is_some()) + .is_some_and(|options| options.commit_quorum.is_some()) { return Err(ErrorKind::InvalidArgument { message: "Specifying a commit quorum to create_index(es) is not supported on \ diff --git a/src/sdam/srv_polling.rs b/src/sdam/srv_polling.rs index cbdf71a4f..8ad686f07 100644 --- a/src/sdam/srv_polling.rs +++ b/src/sdam/srv_polling.rs @@ -33,10 +33,7 @@ impl SrvPollingMonitor { topology_watcher: TopologyWatcher, mut client_options: ClientOptions, ) -> Option { - let initial_info = match client_options.original_srv_info.take() { - Some(info) => info, - None => return None, - }; + let initial_info = client_options.original_srv_info.take()?; Some(Self { initial_hostname: initial_info.hostname,