From ad04e277485eaf29f92fcfb92c2546862c991d8d Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 17 Sep 2024 17:06:22 +0200 Subject: [PATCH] Fix lifetimes of DogstatsDAction Signed-off-by: Bob Weinand --- dogstatsd-client/src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dogstatsd-client/src/lib.rs b/dogstatsd-client/src/lib.rs index 943465b57..e5e1cbb83 100644 --- a/dogstatsd-client/src/lib.rs +++ b/dogstatsd-client/src/lib.rs @@ -24,7 +24,10 @@ const QUEUE_SIZE: usize = 32 * 1024; /// The `DogStatsDActionRef` enum gathers the metric types that can be sent to the DogStatsD server. #[derive(Debug, Serialize, Deserialize)] -pub enum DogStatsDAction<'a, T: AsRef, V: IntoIterator> { +pub enum DogStatsDAction, V> +where + for<'a> &'a V: IntoIterator, +{ // TODO: instead of AsRef we can accept a marker Trait that users of this crate implement Count(T, i64, V), Distribution(T, f64, V), @@ -68,10 +71,10 @@ impl Flusher { Ok(()) } - pub fn send<'a, T: AsRef + 'a, V: IntoIterator>( - &self, - actions: Vec>, - ) { + pub fn send, V>(&self, actions: Vec>) + where + for<'a> &'a V: IntoIterator, + { if self.client.is_none() { return; } @@ -79,20 +82,20 @@ impl Flusher { for action in actions { if let Err(err) = match action { - DogStatsDAction::Count(metric, value, tags) => { + DogStatsDAction::Count(metric, value, ref tags) => { let metric_builder = client.count_with_tags(metric.as_ref(), value); do_send(metric_builder, tags) } - DogStatsDAction::Distribution(metric, value, tags) => { + DogStatsDAction::Distribution(metric, value, ref tags) => { do_send(client.distribution_with_tags(metric.as_ref(), value), tags) } - DogStatsDAction::Gauge(metric, value, tags) => { + DogStatsDAction::Gauge(metric, value, ref tags) => { do_send(client.gauge_with_tags(metric.as_ref(), value), tags) } - DogStatsDAction::Histogram(metric, value, tags) => { + DogStatsDAction::Histogram(metric, value, ref tags) => { do_send(client.histogram_with_tags(metric.as_ref(), value), tags) } - DogStatsDAction::Set(metric, value, tags) => { + DogStatsDAction::Set(metric, value, ref tags) => { do_send(client.set_with_tags(metric.as_ref(), value), tags) } } {