Skip to content

Commit

Permalink
Fix lifetimes of DogstatsDAction
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Sep 17, 2024
1 parent 37fd00e commit ad04e27
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions dogstatsd-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>, V: IntoIterator<Item = &'a Tag>> {
pub enum DogStatsDAction<T: AsRef<str>, V>
where
for<'a> &'a V: IntoIterator<Item = &'a Tag>,
{
// TODO: instead of AsRef<str> we can accept a marker Trait that users of this crate implement
Count(T, i64, V),
Distribution(T, f64, V),
Expand Down Expand Up @@ -68,31 +71,31 @@ impl Flusher {
Ok(())
}

pub fn send<'a, T: AsRef<str> + 'a, V: IntoIterator<Item = &'a Tag>>(
&self,
actions: Vec<DogStatsDAction<'a, T, V>>,
) {
pub fn send<T: AsRef<str>, V>(&self, actions: Vec<DogStatsDAction<T, V>>)
where
for<'a> &'a V: IntoIterator<Item = &'a Tag>,
{
if self.client.is_none() {
return;
}
let client = self.client.as_ref().unwrap();

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)
}
} {
Expand Down

0 comments on commit ad04e27

Please sign in to comment.