use std::collections::BTreeMap;
use std::borrow::Cow;
#[derive(Debug)]
pub enum Value<'a> {
String(&'a str),
Float(f64),
Integer(i64),
Boolean(bool)
}
#[derive(Debug)]
pub struct Measurement<'a> {
pub key: &'a str,
pub timestamp: Option<i64>,
pub fields: BTreeMap<Cow<'a, str>, Value<'a>>,
pub tags: BTreeMap<Cow<'a,str>, Cow<'a,str>>
}
impl<'a> Measurement<'a> {
pub fn new(key: &str) -> Measurement {
Measurement {
key: key,
timestamp: None,
fields: BTreeMap::new(),
tags: BTreeMap::new()
}
}
pub fn add_field<T>(&mut self, field: T, value: Value<'a>) where T: Into<Cow<'a, str>> {
self.fields.insert(field.into(), value);
}
pub fn add_tag<I, K>(&mut self, tag: I, value: K) where I: Into<Cow<'a,str>>, K: Into<Cow<'a, str>> {
self.tags.insert(tag.into(), value.into());
}
pub fn set_timestamp(&mut self, timestamp: i64) {
self.timestamp = Some(timestamp);
}
}