From da652c2617c9857be4147a9d6aa0ba4c7ca4be1d Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Thu, 30 May 2024 18:23:39 +0200 Subject: [PATCH] Clippy fixes --- src/cache/backends/persistent_backend.rs | 8 +++--- src/db/query_models.rs | 2 ++ src/firestore_serde/latlng_serializers.rs | 28 ++++++-------------- src/firestore_serde/reference_serializers.rs | 19 ++++--------- src/firestore_serde/serializer.rs | 14 +++------- src/firestore_serde/timestamp_serializers.rs | 19 ++++--------- 6 files changed, 28 insertions(+), 62 deletions(-) diff --git a/src/cache/backends/persistent_backend.rs b/src/cache/backends/persistent_backend.rs index b538aa5..feff0fb 100644 --- a/src/cache/backends/persistent_backend.rs +++ b/src/cache/backends/persistent_backend.rs @@ -188,7 +188,7 @@ impl FirestorePersistentCacheBackend { fn write_document(&self, doc: &Document) -> FirestoreResult<()> { let (collection_path, document_id) = split_document_path(&doc.name); - if self.config.collections.get(collection_path).is_some() { + if self.config.collections.contains_key(collection_path) { let td: TableDefinition<&str, &[u8]> = TableDefinition::new(collection_path); let write_txn = self.redb.begin_write()?; @@ -338,7 +338,7 @@ impl FirestoreCacheDocsByPathSupport for FirestorePersistentCacheBackend { document_path: &str, ) -> FirestoreResult> { let (collection_path, document_id) = split_document_path(document_path); - if self.config.collections.get(collection_path).is_some() { + if self.config.collections.contains_key(collection_path) { let td: TableDefinition<&str, &[u8]> = TableDefinition::new(collection_path); let read_tx = self.redb.begin_read()?; let table = read_tx.open_table(td)?; @@ -359,7 +359,7 @@ impl FirestoreCacheDocsByPathSupport for FirestorePersistentCacheBackend { collection_path: &str, ) -> FirestoreResult>>> { - if self.config.collections.get(collection_path).is_some() { + if self.config.collections.contains_key(collection_path) { let td: TableDefinition<&str, &[u8]> = TableDefinition::new(collection_path); let read_tx = self.redb.begin_read()?; @@ -388,7 +388,7 @@ impl FirestoreCacheDocsByPathSupport for FirestorePersistentCacheBackend { query: &FirestoreQueryParams, ) -> FirestoreResult>>> { - if self.config.collections.get(collection_path).is_some() { + if self.config.collections.contains_key(collection_path) { // For now only basic/simple query all supported let simple_query_engine = FirestoreCacheQueryEngine::new(query); if simple_query_engine.params_supported() { diff --git a/src/db/query_models.rs b/src/db/query_models.rs index 943ac31..8fcf659 100644 --- a/src/db/query_models.rs +++ b/src/db/query_models.rs @@ -13,6 +13,7 @@ pub enum FirestoreQueryCollection { Group(Vec), } +#[allow(clippy::to_string_trait_impl)] impl ToString for FirestoreQueryCollection { fn to_string(&self) -> String { match self { @@ -312,6 +313,7 @@ pub enum FirestoreQueryDirection { Descending, } +#[allow(clippy::to_string_trait_impl)] impl ToString for FirestoreQueryDirection { fn to_string(&self) -> String { match self { diff --git a/src/firestore_serde/latlng_serializers.rs b/src/firestore_serde/latlng_serializers.rs index d311dd7..69ca31d 100644 --- a/src/firestore_serde/latlng_serializers.rs +++ b/src/firestore_serde/latlng_serializers.rs @@ -30,14 +30,11 @@ pub fn serialize_latlng_for_firestore( type Ok = FirestoreValue; type Error = FirestoreError; - fn serialize_field( + fn serialize_field( &mut self, key: &'static str, value: &T, - ) -> Result<(), Self::Error> - where - T: Serialize, - { + ) -> Result<(), Self::Error> { let serializer = FirestoreValueSerializer { none_as_null: false, }; @@ -63,7 +60,7 @@ pub fn serialize_latlng_for_firestore( FirestoreSerializationError::from_message( "LatLng serializer doesn't recognize the structure of the object", ), - )) + )); } }; @@ -209,10 +206,7 @@ pub fn serialize_latlng_for_firestore( )) } - fn serialize_some(self, value: &T) -> Result - where - T: Serialize, - { + fn serialize_some(self, value: &T) -> Result { value.serialize(self) } @@ -235,27 +229,21 @@ pub fn serialize_latlng_for_firestore( self.serialize_str(variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { Err(FirestoreError::SerializeError( FirestoreSerializationError::from_message( "LatLng serializer doesn't support this type", diff --git a/src/firestore_serde/reference_serializers.rs b/src/firestore_serde/reference_serializers.rs index 0a9a8a1..dfae40b 100644 --- a/src/firestore_serde/reference_serializers.rs +++ b/src/firestore_serde/reference_serializers.rs @@ -207,10 +207,7 @@ pub fn serialize_reference_for_firestore( } } - fn serialize_some(self, value: &T) -> Result - where - T: Serialize, - { + fn serialize_some(self, value: &T) -> Result { value.serialize(self) } @@ -233,27 +230,21 @@ pub fn serialize_reference_for_firestore( self.serialize_str(variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { Err(FirestoreError::SerializeError( FirestoreSerializationError::from_message( "Reference serializer doesn't support this type", diff --git a/src/firestore_serde/serializer.rs b/src/firestore_serde/serializer.rs index bb8c325..18714cf 100644 --- a/src/firestore_serde/serializer.rs +++ b/src/firestore_serde/serializer.rs @@ -465,14 +465,11 @@ impl serde::ser::SerializeStruct for SerializeMap { type Ok = FirestoreValue; type Error = FirestoreError; - fn serialize_field( + fn serialize_field( &mut self, key: &'static str, value: &T, - ) -> Result<(), Self::Error> - where - T: Serialize, - { + ) -> Result<(), Self::Error> { let serializer = FirestoreValueSerializer { none_as_null: self.none_as_null, }; @@ -500,14 +497,11 @@ impl serde::ser::SerializeStructVariant for SerializeStructVariant { type Ok = FirestoreValue; type Error = FirestoreError; - fn serialize_field( + fn serialize_field( &mut self, key: &'static str, value: &T, - ) -> Result<(), Self::Error> - where - T: Serialize, - { + ) -> Result<(), Self::Error> { let serializer = FirestoreValueSerializer { none_as_null: self.none_as_null, }; diff --git a/src/firestore_serde/timestamp_serializers.rs b/src/firestore_serde/timestamp_serializers.rs index ef08ac9..3a94f3d 100644 --- a/src/firestore_serde/timestamp_serializers.rs +++ b/src/firestore_serde/timestamp_serializers.rs @@ -231,10 +231,7 @@ pub fn serialize_timestamp_for_firestore( } } - fn serialize_some(self, value: &T) -> Result - where - T: Serialize, - { + fn serialize_some(self, value: &T) -> Result { value.serialize(self) } @@ -257,27 +254,21 @@ pub fn serialize_timestamp_for_firestore( self.serialize_str(variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, - ) -> Result - where - T: Serialize, - { + ) -> Result { Err(FirestoreError::SerializeError( FirestoreSerializationError::from_message( "Timestamp serializer doesn't support this type",