Skip to content

Commit 089f26f

Browse files
authored
Merge pull request #1161 from athre0z/caching-session-debug-impl
Add working `Debug` impl for caching session
2 parents 6abf82d + dc2e939 commit 089f26f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

scylla/src/transport/caching_session.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use scylla_cql::frame::response::result::{PreparedMetadata, ResultMetadata};
1616
use scylla_cql::types::serialize::batch::BatchValues;
1717
use scylla_cql::types::serialize::row::SerializeRow;
1818
use std::collections::hash_map::RandomState;
19+
use std::fmt;
1920
use std::hash::BuildHasher;
2021
use std::sync::Arc;
2122

@@ -39,7 +40,6 @@ struct RawPreparedStatementData {
3940
}
4041

4142
/// Provides auto caching while executing queries
42-
#[derive(Debug)]
4343
pub struct GenericCachingSession<DeserializationApi, S = RandomState>
4444
where
4545
S: Clone + BuildHasher,
@@ -53,6 +53,20 @@ where
5353
cache: DashMap<String, RawPreparedStatementData, S>,
5454
}
5555

56+
impl<DeserializationApi, S> fmt::Debug for GenericCachingSession<DeserializationApi, S>
57+
where
58+
S: Clone + BuildHasher,
59+
DeserializationApi: DeserializationApiKind,
60+
{
61+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62+
f.debug_struct("GenericCachingSession")
63+
.field("session", &self.session)
64+
.field("max_capacity", &self.max_capacity)
65+
.field("cache", &self.cache)
66+
.finish()
67+
}
68+
}
69+
5670
pub type CachingSession<S = RandomState> = GenericCachingSession<CurrentDeserializationApi, S>;
5771

5872
#[deprecated(
@@ -335,6 +349,8 @@ mod tests {
335349
use crate::transport::partitioner::PartitionerName;
336350
use crate::transport::session::Session;
337351
use crate::utils::test_utils::unique_keyspace_name;
352+
#[allow(deprecated)]
353+
use crate::LegacyCachingSession;
338354
use crate::{
339355
batch::{Batch, BatchStatement},
340356
prepared_statement::PreparedStatement,
@@ -766,4 +782,12 @@ mod tests {
766782
verify_partitioner().await;
767783
verify_partitioner().await;
768784
}
785+
786+
// NOTE: intentionally no `#[test]`: this is a compile-time test
787+
fn _caching_session_impls_debug() {
788+
fn assert_debug<T: std::fmt::Debug>() {}
789+
assert_debug::<CachingSession>();
790+
#[allow(deprecated)]
791+
assert_debug::<LegacyCachingSession>();
792+
}
769793
}

0 commit comments

Comments
 (0)