From 3b83c932c54ef62a9081ff92f23f68f7548cce2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Sat, 28 Dec 2024 15:28:14 +0100 Subject: [PATCH 1/2] scylla: add working `Debug` impl for caching session The previous derived implementation was not actually usable because it had `Debug` bounds on the type parameters. The `RandomState` default value for the `S` argument does not impl `Debug`, so this didn't work. This commit switches to a manual `Debug` impl that doesn't have these unnecessary bounds. --- scylla/src/transport/caching_session.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scylla/src/transport/caching_session.rs b/scylla/src/transport/caching_session.rs index 77668b28c..debf0def6 100644 --- a/scylla/src/transport/caching_session.rs +++ b/scylla/src/transport/caching_session.rs @@ -16,6 +16,7 @@ use scylla_cql::frame::response::result::{PreparedMetadata, ResultMetadata}; use scylla_cql::types::serialize::batch::BatchValues; use scylla_cql::types::serialize::row::SerializeRow; use std::collections::hash_map::RandomState; +use std::fmt; use std::hash::BuildHasher; use std::sync::Arc; @@ -39,7 +40,6 @@ struct RawPreparedStatementData { } /// Provides auto caching while executing queries -#[derive(Debug)] pub struct GenericCachingSession where S: Clone + BuildHasher, @@ -53,6 +53,20 @@ where cache: DashMap, } +impl fmt::Debug for GenericCachingSession +where + S: Clone + BuildHasher, + DeserializationApi: DeserializationApiKind, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("GenericCachingSession") + .field("session", &self.session) + .field("max_capacity", &self.max_capacity) + .field("cache", &self.cache) + .finish() + } +} + pub type CachingSession = GenericCachingSession; #[deprecated( From dc2e939ee847b1b5ba89ebe662aae89e84f3a9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Sat, 28 Dec 2024 15:41:19 +0100 Subject: [PATCH 2/2] scylla: static assert ensuring caching session impls `Debug` --- scylla/src/transport/caching_session.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scylla/src/transport/caching_session.rs b/scylla/src/transport/caching_session.rs index debf0def6..a5b641683 100644 --- a/scylla/src/transport/caching_session.rs +++ b/scylla/src/transport/caching_session.rs @@ -349,6 +349,8 @@ mod tests { use crate::transport::partitioner::PartitionerName; use crate::transport::session::Session; use crate::utils::test_utils::unique_keyspace_name; + #[allow(deprecated)] + use crate::LegacyCachingSession; use crate::{ batch::{Batch, BatchStatement}, prepared_statement::PreparedStatement, @@ -780,4 +782,12 @@ mod tests { verify_partitioner().await; verify_partitioner().await; } + + // NOTE: intentionally no `#[test]`: this is a compile-time test + fn _caching_session_impls_debug() { + fn assert_debug() {} + assert_debug::(); + #[allow(deprecated)] + assert_debug::(); + } }