nom_openmetrics/
metric_descriptor.rs1#[derive(Debug, PartialEq)]
3pub enum MetricDescriptor<'a> {
4    Type {
6        metric: &'a str,
7        r#type: MetricType<'a>,
8    },
9    Help { metric: &'a str, help: String },
11    Unit { metric: &'a str, unit: &'a str },
13}
14
15impl<'a> MetricDescriptor<'a> {
16    pub fn help(metric: &'a str, help: String) -> Self {
18        Self::Help { metric, help }
19    }
20
21    pub fn r#type(metric: &'a str, r#type: MetricType<'a>) -> Self {
23        Self::Type { metric, r#type }
24    }
25
26    pub fn unit(metric: &'a str, unit: &'a str) -> Self {
28        Self::Unit { metric, unit }
29    }
30
31    pub fn metric(&self) -> &'a str {
33        match self {
34            MetricDescriptor::Type { metric, .. }
35            | MetricDescriptor::Help { metric, .. }
36            | MetricDescriptor::Unit { metric, .. } => metric,
37        }
38    }
39}
40
41#[derive(Debug, PartialEq, strum::Display)]
43pub enum MetricType<'a> {
44    Counter,
46    Gauge,
48    Gaugehistogram,
50    Histogram,
52    Info,
54    Stateset,
56    Summary,
58    #[strum(to_string = "{0}")]
60    Unknown(&'a str),
61}