Browse Source

adds a shortcut version of each "function" when column name = variable name!

master
Jonathan Strong 7 years ago
parent
commit
71dee1f783
2 changed files with 15 additions and 1 deletions
  1. +1
    -1
      Cargo.toml
  2. +14
    -0
      src/influx.rs

+ 1
- 1
Cargo.toml View File

@@ -1,6 +1,6 @@
[package] [package]
name = "logging" name = "logging"
version = "0.2.0"
version = "0.2.1"
authors = ["Jonathan Strong <jstrong@legis.io>"] authors = ["Jonathan Strong <jstrong@legis.io>"]


[dependencies] [dependencies]


+ 14
- 0
src/influx.rs View File

@@ -117,6 +117,7 @@ macro_rules! measure {
(@kv $t:tt, $meas:ident, $k:tt, $v:expr) => { measure!(@ea $t, $meas, stringify!($k), $v) }; (@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 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 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 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 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)) }; (@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 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 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)) }; (@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) => {0usize};
(@count_tags tag $($tail:tt)*) => {1usize + measure!(@count_tags $($tail)*)}; (@count_tags tag $($tail:tt)*) => {1usize + measure!(@count_tags $($tail)*)};
@@ -619,6 +622,17 @@ mod tests {
use super::*; use super::*;
use test::{black_box, Bencher}; 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] #[test]
fn it_uses_measure_macro_parenthesis_syntax() { 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)); let m = measure!(@make_meas test, t(a,"b"), i(n,1), f(x,1.1), tm(1));


Loading…
Cancel
Save