From b69b8cc6517de1c5dfdfb82306d6cd873a947f17 Mon Sep 17 00:00:00 2001 From: Arthur Silva Date: Sun, 15 Sep 2024 13:29:24 +0200 Subject: [PATCH] fix clone when stats feature is enabled --- src/shard.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/shard.rs b/src/shard.rs index 3d8e51c..64a7eb0 100644 --- a/src/shard.rs +++ b/src/shard.rs @@ -72,7 +72,6 @@ enum Entry { /// A bounded cache using a modified CLOCK-PRO eviction policy. /// The implementation allows some parallelism as gets don't require exclusive access. /// Any evicted items are returned so they can be dropped by the caller, outside the locks. -#[derive(Clone)] pub struct CacheShard { hash_builder: B, /// Map to an entry in the `entries` slab. @@ -102,6 +101,35 @@ pub struct CacheShard { pub(crate) lifecycle: L, } +impl Clone + for CacheShard +{ + fn clone(&self) -> Self { + Self { + hash_builder: self.hash_builder.clone(), + map: self.map.clone(), + entries: self.entries.clone(), + cold_head: self.cold_head, + hot_head: self.hot_head, + ghost_head: self.ghost_head, + weight_target_hot: self.weight_target_hot, + weight_capacity: self.weight_capacity, + weight_hot: self.weight_hot, + weight_cold: self.weight_cold, + num_hot: self.num_hot, + num_cold: self.num_cold, + num_non_resident: self.num_non_resident, + capacity_non_resident: self.capacity_non_resident, + #[cfg(feature = "stats")] + hits: self.hits.load(atomic::Ordering::Relaxed).into(), + #[cfg(feature = "stats")] + misses: self.misses.load(atomic::Ordering::Relaxed).into(), + weighter: self.weighter.clone(), + lifecycle: self.lifecycle.clone(), + } + } +} + #[cfg(feature = "stats")] macro_rules! record_hit { ($self: expr) => {{