From 71dee1f78391b4614dd6da6f1d28190594f5f950 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Fri, 8 Dec 2017 03:44:18 -0500 Subject: [PATCH] adds a shortcut version of each "function" when column name = variable name! --- Cargo.toml | 2 +- src/influx.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index aa42611..f182e85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "logging" -version = "0.2.0" +version = "0.2.1" authors = ["Jonathan Strong "] [dependencies] diff --git a/src/influx.rs b/src/influx.rs index 7a6afc8..131cec9 100644 --- a/src/influx.rs +++ b/src/influx.rs @@ -117,6 +117,7 @@ macro_rules! measure { (@kv $t:tt, $meas:ident, $k:tt, $v:expr) => { measure!(@ea $t, $meas, stringify!($k), $v) }; (@kv time, $meas:ident, $tm:expr) => { $meas = $meas.set_timestamp($tm as i64) }; (@kv tm, $meas:ident, $tm:expr) => { $meas = $meas.set_timestamp($tm as i64) }; + (@kv $t:tt, $meas:ident, $k:tt) => { measure!(@ea $t, $meas, stringify!($k), measure!(@as_expr $k)) }; (@ea tag, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_tag($k, $v); }; (@ea t, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_tag($k, $v); }; (@ea int, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_field($k, $crate::influx::OwnedValue::Integer($v as i64)) }; @@ -131,6 +132,8 @@ macro_rules! measure { (@ea u, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_field($k, $crate::influx::OwnedValue::Uuid($v)) }; (@ea bool, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_field($k, $crate::influx::OwnedValue::Boolean($v as bool)) }; (@ea b, $meas:ident, $k:expr, $v:expr) => { $meas = $meas.add_field($k, $crate::influx::OwnedValue::Boolean($v as bool)) }; + + (@as_expr $e:expr) => {$e}; (@count_tags) => {0usize}; (@count_tags tag $($tail:tt)*) => {1usize + measure!(@count_tags $($tail)*)}; @@ -619,6 +622,17 @@ mod tests { use super::*; use test::{black_box, Bencher}; + #[test] + fn it_uses_the_new_tag_k_only_shortcut() { + let tag_value = "one"; + let color = "red"; + let time = now(); + let m = measure!(@make_meas test, t(color), t(tag_value), tm(time)); + assert_eq!(m.tags.get("color"), Some(&"red")); + assert_eq!(m.tags.get("tag_value"), Some(&"one")); + assert_eq!(m.timestamp, Some(time)); + } + #[test] fn it_uses_measure_macro_parenthesis_syntax() { let m = measure!(@make_meas test, t(a,"b"), i(n,1), f(x,1.1), tm(1));