From e7a00d9cf37f2eef0424143b2ba1baa9854cbe50 Mon Sep 17 00:00:00 2001 From: Francis Lalonde Date: Tue, 12 Jul 2022 14:11:39 -0400 Subject: [PATCH] Clippy fixes --- Cargo.toml | 10 +++++----- src/atomic.rs | 13 +++++++------ src/attributes.rs | 2 +- src/macros.rs | 2 +- src/output/format.rs | 2 +- src/output/statsd.rs | 8 +++++--- src/pcg32.rs | 2 +- src/proxy.rs | 2 +- src/scheduler.rs | 4 ++-- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98f834e..338ca16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "dipstick" -version = "0.9.0" +version = "0.9.1" authors = ["Francis Lalonde "] -description = """A fast, all-purpose metrics library decoupling instrumentation from reporting backends. - Similar to popular logging frameworks, but with counters, timers and gauges. - Can combine outputs (e.g. log + graphite), do sampling, aggregation, periodical publication, etc.""" +description = """Fast, all-purpose metrics library decoupling instrumentation from reporting backends. + Like logging frameworks but with counters, timers and gauges. + Supports combined outputs (e.g. log + graphite), sampling, aggregation, scheduled push, etc.""" documentation = "https://docs.rs/dipstick" homepage = "https://github.com/fralalonde/dipstick" @@ -13,7 +13,7 @@ repository = "https://github.com/fralalonde/dipstick" readme = "README.md" keywords = ["metrics", "statsd", "graphite", "timer", "prometheus"] license = "MIT/Apache-2.0" -edition = "2018" +edition = "2021" [badges] travis-ci = { repository = "fralalonde/dipstick", branch = "master" } diff --git a/src/atomic.rs b/src/atomic.rs index c07c087..676890e 100755 --- a/src/atomic.rs +++ b/src/atomic.rs @@ -107,11 +107,9 @@ impl InnerAtomicBucket { .metrics .iter() .flat_map(|(name, scores)| { - if let Some(values) = scores.reset(duration_seconds) { - Some((name, scores.metric_kind(), values)) - } else { - None - } + scores + .reset(duration_seconds) + .map(|values| (name, scores.metric_kind(), values)) }) .collect(); @@ -429,7 +427,10 @@ impl AtomicScores { fn swap_if(counter: &AtomicIsize, new_value: isize, compare: fn(isize, isize) -> bool) { let mut current = counter.load(Acquire); while compare(new_value, current) { - if counter.compare_and_swap(current, new_value, Release) == new_value { + if counter + .compare_exchange(current, new_value, Relaxed, Relaxed) + .is_ok() + { // update successful break; } diff --git a/src/attributes.rs b/src/attributes.rs index 6ff6a74..7bd8139 100755 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -73,7 +73,7 @@ pub type Shared = Arc>; pub struct Listener { listener_id: usize, - listener_fn: Arc () + Send + Sync + 'static>, + listener_fn: Arc, } /// Attributes common to metric components. diff --git a/src/macros.rs b/src/macros.rs index d962e62..ca71247 100755 --- a/src/macros.rs +++ b/src/macros.rs @@ -51,7 +51,7 @@ macro_rules! labels { $( let _ = _map.insert($key.into(), ::std::sync::Arc::new($value.into())); )* - crate::Labels::from(_map) + $crate::Labels::from(_map) } }; () => { diff --git a/src/output/format.rs b/src/output/format.rs index 822218b..1806b67 100644 --- a/src/output/format.rs +++ b/src/output/format.rs @@ -95,7 +95,7 @@ pub trait LineFormat: Send + Sync { #[derive(Default)] pub struct SimpleFormat { // TODO make separator configurable -// separator: String, + // separator: String, } impl LineFormat for SimpleFormat { diff --git a/src/output/statsd.rs b/src/output/statsd.rs index efcabf2..40637bc 100755 --- a/src/output/statsd.rs +++ b/src/output/statsd.rs @@ -10,6 +10,7 @@ use crate::name::MetricName; use crate::pcg32; use crate::{CachedInput, QueuedInput}; use crate::{Flush, MetricValue}; +use std::fmt::Write; use std::net::ToSocketAddrs; use std::net::UdpSocket; @@ -49,9 +50,11 @@ impl Statsd { } impl Buffered for Statsd {} + impl Sampled for Statsd {} impl QueuedInput for Statsd {} + impl CachedInput for Statsd {} impl Input for Statsd { @@ -109,7 +112,7 @@ impl InputScope for StatsdScope { let metric_id = MetricId::forge("statsd", name); if let Sampling::Random(float_rate) = self.get_sampling() { - suffix.push_str(&format! {"|@{}\n", float_rate}); + let _ = write!(suffix, "|@{}\n", float_rate); let int_sampling_rate = pcg32::to_int_rate(float_rate); let metric = StatsdMetric { prefix, @@ -123,7 +126,7 @@ impl InputScope for StatsdScope { } }) } else { - suffix.push_str("\n"); + suffix.push('\n'); let metric = StatsdMetric { prefix, suffix, @@ -262,7 +265,6 @@ impl Drop for StatsdScope { #[cfg(feature = "bench")] mod bench { - use super::*; use crate::attributes::*; use crate::input::*; diff --git a/src/pcg32.rs b/src/pcg32.rs index d5bd339..7684b77 100644 --- a/src/pcg32.rs +++ b/src/pcg32.rs @@ -39,7 +39,7 @@ fn pcg32_random() -> u32 { /// all | 1.0 | 0x0 | 100% /// none | 0.0 | 0xFFFFFFFF | 0% pub fn to_int_rate(float_rate: f64) -> u32 { - assert!(float_rate <= 1.0 && float_rate >= 0.0); + assert!((0.0..=1.0).contains(&float_rate)); ((1.0 - float_rate) * f64::from(::std::u32::MAX)) as u32 } diff --git a/src/proxy.rs b/src/proxy.rs index 0319cd6..f6dd61a 100755 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -236,7 +236,7 @@ impl InputScope for Proxy { .metrics .get(&name) // TODO validate that InputKind matches existing - .and_then(|proxy_ref| Weak::upgrade(proxy_ref)) + .and_then(Weak::upgrade) .unwrap_or_else(|| { let namespace = &*name; { diff --git a/src/scheduler.rs b/src/scheduler.rs index 97f1da9..0e9c9b8 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -102,7 +102,7 @@ struct ScheduledTask { next_time: Instant, period: Duration, handle: CancelHandle, - operation: Arc () + Send + Sync + 'static>, + operation: Arc, } impl Ord for ScheduledTask { @@ -185,7 +185,7 @@ impl Scheduler { /// Schedule a task to run periodically. pub fn schedule(&self, period: Duration, operation: F) -> CancelHandle where - F: Fn(Instant) -> () + Send + Sync + 'static, + F: Fn(Instant) + Send + Sync + 'static, { let handle = CancelHandle::new(); let new_task = ScheduledTask {