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
37
38
39
40
41
42
43
44
45
46
use std::fmt;

use crate::{Exemplar, MetricNumber, ParseError, Timestamp};

use super::{MetricFamilyMarshal, MetricValueMarshal};

pub trait MetricsType {
    fn can_have_exemplar(&self, metric_name: &str) -> bool;
    fn can_have_units(&self) -> bool;
    fn can_have_multiple_lines(&self) -> bool;
    fn get_ignored_labels(&self, metric_name: &str) -> &[&str];
    fn get_type_value(&self) -> MetricValueMarshal;
}

pub trait MarshalledMetricFamily {
    type Error;
    fn process_new_metric(
        &mut self,
        metric_name: &str,
        value: MetricNumber,
        label_names: Vec<String>,
        label_values: Vec<String>,
        timestamp: Option<Timestamp>,
        exemplar: Option<Exemplar>,
    ) -> Result<(), Self::Error>;

    fn validate(&self) -> Result<(), ParseError>;
}

pub trait MarshalledMetric<T>
where
    T: MetricsType,
{
    fn validate(&self, family: &MetricFamilyMarshal<T>) -> Result<(), ParseError>;
}

pub trait RenderableMetricValue {
    fn render(
        &self,
        f: &mut fmt::Formatter<'_>,
        metric_name: &str,
        timestamp: Option<&Timestamp>,
        label_names: &[&str],
        label_values: &[&str],
    ) -> fmt::Result;
}