1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::event::Event;

pub(crate) const fn check_is_metric(e: Event) -> (bool, Event) {
    (matches!(e, Event::Metric(_)), e)
}

pub(crate) fn check_is_metric_with_context(e: Event) -> (Result<(), String>, Event) {
    let (result, event) = check_is_metric(e);
    if result {
        (Ok(()), event)
    } else {
        (Err("event is not a metric type".to_string()), event)
    }
}

#[cfg(test)]
mod test {
    use super::check_is_metric;
    use crate::event::{
        metric::{Metric, MetricKind, MetricValue},
        Event, LogEvent,
    };

    #[test]
    fn is_metric_basic() {
        assert!(!check_is_metric(Event::from(LogEvent::from("just a log"))).0);
        assert!(
            check_is_metric(Event::from(Metric::new(
                "test metric",
                MetricKind::Incremental,
                MetricValue::Counter { value: 1.0 },
            )))
            .0,
        );
    }
}