From f501aef37008b846934998abcc9f14ae59ec308e Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Sun, 26 Nov 2023 16:35:15 -0800 Subject: [PATCH] Clippy + fmt --- crates/bonsaidb-core/src/key/time.rs | 2 +- crates/bonsaidb-core/src/schema/schematic.rs | 7 ++----- crates/bonsaidb-files/src/direct.rs | 2 +- crates/bonsaidb-local/src/database/keyvalue.rs | 2 +- crates/bonsaidb-local/src/database/pubsub.rs | 2 +- crates/bonsaidb-local/src/hpke_util.rs | 9 ++++----- crates/bonsaidb-local/src/storage/argon.rs | 2 +- crates/bonsaidb-local/src/tasks/manager/jobs.rs | 2 +- crates/bonsaidb-local/src/vault.rs | 10 +++++----- crates/bonsaidb-local/src/views/mapper.rs | 2 +- crates/bonsaidb-macros/src/lib.rs | 2 +- 11 files changed, 19 insertions(+), 23 deletions(-) diff --git a/crates/bonsaidb-core/src/key/time.rs b/crates/bonsaidb-core/src/key/time.rs index 5d301195585..c3f78ea2136 100644 --- a/crates/bonsaidb-core/src/key/time.rs +++ b/crates/bonsaidb-core/src/key/time.rs @@ -1023,7 +1023,7 @@ pub mod limited { /// to be converted to a value relative to the unix epoch. pub fn to_timestamp_string(&self) -> Result { let mut string = String::new(); - self.display(&mut string).map(|_| string) + self.display(&mut string).map(|()| string) } fn display(&self, f: &mut impl Write) -> Result<(), TimeError> { diff --git a/crates/bonsaidb-core/src/schema/schematic.rs b/crates/bonsaidb-core/src/schema/schematic.rs index 706b81e6dd4..fdcbbf342da 100644 --- a/crates/bonsaidb-core/src/schema/schematic.rs +++ b/crates/bonsaidb-core/src/schema/schematic.rs @@ -98,13 +98,10 @@ impl Schematic { let unique_views = self .eager_views_by_collection .entry(collection.clone()) - .or_insert_with(Vec::new); + .or_default(); unique_views.push(TypeId::of::()); } - let views = self - .views_by_collection - .entry(collection) - .or_insert_with(Vec::new); + let views = self.views_by_collection.entry(collection).or_default(); views.push(TypeId::of::()); Ok(()) diff --git a/crates/bonsaidb-files/src/direct.rs b/crates/bonsaidb-files/src/direct.rs index 784351d3136..ed101a5d512 100644 --- a/crates/bonsaidb-files/src/direct.rs +++ b/crates/bonsaidb-files/src/direct.rs @@ -1311,7 +1311,7 @@ impl<'a, Config: FileConfig, Database: AsyncConnection + Clone + 'static> tokio: } } else if self.buffer.capacity() == self.buffer.len() { match ready!(std::pin::Pin::new(&mut self).poll_flush(cx)) { - Ok(_) => {} + Ok(()) => {} Err(err) => { return Poll::Ready(Err(err)); } diff --git a/crates/bonsaidb-local/src/database/keyvalue.rs b/crates/bonsaidb-local/src/database/keyvalue.rs index 22eacc4bd34..7df649c28aa 100644 --- a/crates/bonsaidb-local/src/database/keyvalue.rs +++ b/crates/bonsaidb-local/src/database/keyvalue.rs @@ -788,7 +788,7 @@ pub fn background_worker( // fails. So, we will cap the sleep time at 1 day. let remaining = remaining.min(Duration::from_secs(60 * 60 * 24)); match timestamp_receiver.watch_timeout(remaining) { - Ok(_) | Err(watchable::TimeoutError::Timeout) => { + Ok(()) | Err(watchable::TimeoutError::Timeout) => { perform_operations = true; } Err(watchable::TimeoutError::Disconnected) => break, diff --git a/crates/bonsaidb-local/src/database/pubsub.rs b/crates/bonsaidb-local/src/database/pubsub.rs index 74e6c4bdf2c..5045444e78d 100644 --- a/crates/bonsaidb-local/src/database/pubsub.rs +++ b/crates/bonsaidb-local/src/database/pubsub.rs @@ -48,7 +48,7 @@ impl PubSub for super::Database { pubsub_topic_resource_name(self.name(), &topic), &BonsaiAction::Database(DatabaseAction::PubSub(PubSubAction::Publish)), ) - .map(|_| OwnedBytes::from(database_topic(&self.data.name, &topic))) + .map(|()| OwnedBytes::from(database_topic(&self.data.name, &topic))) }) .collect::, _>>()?, payload, diff --git a/crates/bonsaidb-local/src/hpke_util.rs b/crates/bonsaidb-local/src/hpke_util.rs index 8ec8c927360..98117c2dd55 100644 --- a/crates/bonsaidb-local/src/hpke_util.rs +++ b/crates/bonsaidb-local/src/hpke_util.rs @@ -1,9 +1,8 @@ use generic_array::GenericArray; -use hpke::{ - kem::{DhP256HkdfSha256, Kem as KemTrait}, - Deserializable, Serializable, -}; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use hpke::kem::{DhP256HkdfSha256, Kem as KemTrait}; +use hpke::{Deserializable, Serializable}; +use serde::de::Error; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; // Helpful aliases for the HPKE types we use in vault encryption diff --git a/crates/bonsaidb-local/src/storage/argon.rs b/crates/bonsaidb-local/src/storage/argon.rs index b201060ebae..3eba0689d4f 100644 --- a/crates/bonsaidb-local/src/storage/argon.rs +++ b/crates/bonsaidb-local/src/storage/argon.rs @@ -197,7 +197,7 @@ impl HashingThread { let argon = Argon2::new(algorithm, version, argon2::Params::try_from(&hash)?); hash.verify_password(&[&argon], request.password.0.as_bytes()) - .map(|_| HashResponse::Verified) + .map(|()| HashResponse::Verified) .map_err(Error::from) } diff --git a/crates/bonsaidb-local/src/tasks/manager/jobs.rs b/crates/bonsaidb-local/src/tasks/manager/jobs.rs index f4437870017..8541bc6ba7e 100644 --- a/crates/bonsaidb-local/src/tasks/manager/jobs.rs +++ b/crates/bonsaidb-local/src/tasks/manager/jobs.rs @@ -80,7 +80,7 @@ where id: Id, ) -> Handle { let (sender, receiver) = flume::bounded(1); - let senders = self.result_senders.entry(id).or_insert_with(Vec::default); + let senders = self.result_senders.entry(id).or_default(); senders.push(Box::new(sender)); Handle { id, receiver } diff --git a/crates/bonsaidb-local/src/vault.rs b/crates/bonsaidb-local/src/vault.rs index d244dcdf696..fa3dc2d5cd2 100644 --- a/crates/bonsaidb-local/src/vault.rs +++ b/crates/bonsaidb-local/src/vault.rs @@ -48,11 +48,6 @@ //! used directly. This variant of `ChaCha20Poly1305` extends the nonce from 12 //! bytes to 24 bytes, which allows for random nonces to be used. -use crate::hpke_util::{ - serde_encapped_key, serde_privkey, serde_pubkey, VaultP256EncappedKey, VaultP256Kem, - VaultP256PrivateKey, VaultP256PublicKey, -}; - use std::borrow::Cow; use std::collections::HashMap; use std::fmt::{Debug, Display}; @@ -76,6 +71,11 @@ use rand::{thread_rng, Rng}; use serde::{Deserialize, Serialize}; use zeroize::{Zeroize, Zeroizing}; +use crate::hpke_util::{ + serde_encapped_key, serde_privkey, serde_pubkey, VaultP256EncappedKey, VaultP256Kem, + VaultP256PrivateKey, VaultP256PublicKey, +}; + /// A private encryption key. #[derive(Serialize, Deserialize)] pub enum KeyPair { diff --git a/crates/bonsaidb-local/src/views/mapper.rs b/crates/bonsaidb-local/src/views/mapper.rs index 4d8a20e6b71..98360b37378 100644 --- a/crates/bonsaidb-local/src/views/mapper.rs +++ b/crates/bonsaidb-local/src/views/mapper.rs @@ -253,7 +253,7 @@ impl<'a> DocumentRequest<'a> { let key_mappings = batch .new_mappings .entry(ArcBytes::from(mapping.key.to_vec())) - .or_insert_with(Vec::default); + .or_default(); key_mappings.push(mapping); } } diff --git a/crates/bonsaidb-macros/src/lib.rs b/crates/bonsaidb-macros/src/lib.rs index e30f01fb1d1..775a65e3de3 100644 --- a/crates/bonsaidb-macros/src/lib.rs +++ b/crates/bonsaidb-macros/src/lib.rs @@ -54,7 +54,7 @@ fn core_path() -> Path { () if cfg!(feature = "server-path") => parse_quote!(::bonsaidb_server::core), () if cfg!(feature = "local-path") => parse_quote!(::bonsaidb_local::core), () if cfg!(feature = "client-path") => parse_quote!(::bonsaidb_client::core), - _ => parse_quote!(::bonsaidb_core), + () => parse_quote!(::bonsaidb_core), }, }, }