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));