diff --git a/limitador/src/counter.rs b/limitador/src/counter.rs index efd486e7..9763d627 100644 --- a/limitador/src/counter.rs +++ b/limitador/src/counter.rs @@ -40,6 +40,7 @@ impl Counter { } } + #[cfg(any(feature = "redis_storage", feature = "disk_storage"))] pub(crate) fn key(&self) -> Self { Self { limit: self.limit.clone(), diff --git a/limitador/src/storage/atomic_expiring_value.rs b/limitador/src/storage/atomic_expiring_value.rs index f8d19ee0..c661ca08 100644 --- a/limitador/src/storage/atomic_expiring_value.rs +++ b/limitador/src/storage/atomic_expiring_value.rs @@ -27,7 +27,7 @@ impl AtomicExpiringValue { self.value_at(SystemTime::now()) } - #[allow(dead_code)] + #[cfg(feature = "redis_storage")] pub fn add_and_set_expiry(&self, delta: u64, expiry: SystemTime) -> u64 { self.expiry.update(expiry); self.value.fetch_add(delta, Ordering::SeqCst) + delta @@ -59,11 +59,6 @@ impl AtomicExpiryTime { } } - #[allow(dead_code)] - pub fn from_now(ttl: Duration) -> Self { - Self::new(SystemTime::now() + ttl) - } - fn since_epoch(when: SystemTime) -> u64 { when.duration_since(UNIX_EPOCH) .expect("SystemTime before UNIX EPOCH!") @@ -83,7 +78,7 @@ impl AtomicExpiryTime { self.expiry.load(Ordering::SeqCst) <= when } - #[allow(dead_code)] + #[cfg(feature = "redis_storage")] pub fn update(&self, expiry: SystemTime) { self.expiry .store(Self::since_epoch(expiry), Ordering::SeqCst); diff --git a/limitador/src/storage/redis/counters_cache.rs b/limitador/src/storage/redis/counters_cache.rs index ef28413b..15be4fdf 100644 --- a/limitador/src/storage/redis/counters_cache.rs +++ b/limitador/src/storage/redis/counters_cache.rs @@ -41,6 +41,7 @@ impl CachedCounterValue { } } + #[cfg(feature = "redis_storage")] pub fn add_from_authority(&self, delta: u64, expire_at: SystemTime, max_value: u64) { let new_val = self.value.add_and_set_expiry(delta, expire_at); if new_val > max_value { diff --git a/limitador/tests/helpers/tests_limiter.rs b/limitador/tests/helpers/tests_limiter.rs index b7bc4ca9..2bae0c3e 100644 --- a/limitador/tests/helpers/tests_limiter.rs +++ b/limitador/tests/helpers/tests_limiter.rs @@ -10,7 +10,7 @@ use std::collections::{HashMap, HashSet}; enum LimiterImpl { Blocking(RateLimiter), - #[allow(dead_code)] // dead when no "redis_storage" + #[cfg(feature = "redis_storage")] Async(AsyncRateLimiter), } @@ -25,7 +25,7 @@ impl TestsLimiter { } } - #[allow(dead_code)] // dead when no "redis_storage" + #[cfg(feature = "redis_storage")] pub fn new_from_async_impl(limiter: AsyncRateLimiter) -> Self { Self { limiter_impl: LimiterImpl::Async(limiter), diff --git a/limitador/tests/integration_tests.rs b/limitador/tests/integration_tests.rs index 06c308c2..1e66b8c1 100644 --- a/limitador/tests/integration_tests.rs +++ b/limitador/tests/integration_tests.rs @@ -21,6 +21,7 @@ macro_rules! test_with_all_storage_impls { $function(&mut TestsLimiter::new_from_blocking_impl(rate_limiter)).await; } + #[cfg(feature = "disk_storage")] #[tokio::test] async fn [<$function _disk_storage>]() { let dir = TempDir::new().expect("We should have a dir!"); @@ -96,6 +97,7 @@ mod test { use self::limitador::RateLimiter; use crate::helpers::tests_limiter::*; use limitador::limit::Limit; + #[cfg(feature = "disk_storage")] use limitador::storage::disk::{DiskStorage, OptimizeFor}; #[cfg(feature = "distributed_storage")] use limitador::storage::distributed::CrInMemoryStorage; @@ -103,6 +105,7 @@ mod test { use std::collections::{HashMap, HashSet}; use std::thread::sleep; use std::time::Duration; + #[cfg(feature = "disk_storage")] use tempfile::TempDir; test_with_all_storage_impls!(get_namespaces);