Skip to content

Commit

Permalink
Merge pull request #1161 from athre0z/caching-session-debug-impl
Browse files Browse the repository at this point in the history
Add working `Debug` impl for caching session
  • Loading branch information
wprzytula authored Dec 29, 2024
2 parents 6abf82d + dc2e939 commit 089f26f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,7 +40,6 @@ struct RawPreparedStatementData {
}

/// Provides auto caching while executing queries
#[derive(Debug)]
pub struct GenericCachingSession<DeserializationApi, S = RandomState>
where
S: Clone + BuildHasher,
Expand All @@ -53,6 +53,20 @@ where
cache: DashMap<String, RawPreparedStatementData, S>,
}

impl<DeserializationApi, S> fmt::Debug for GenericCachingSession<DeserializationApi, S>
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<S = RandomState> = GenericCachingSession<CurrentDeserializationApi, S>;

#[deprecated(
Expand Down Expand Up @@ -335,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,
Expand Down Expand Up @@ -766,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<T: std::fmt::Debug>() {}
assert_debug::<CachingSession>();
#[allow(deprecated)]
assert_debug::<LegacyCachingSession>();
}
}

0 comments on commit 089f26f

Please sign in to comment.