openmetrics_parser/internal/
traits.rs

1use std::fmt;
2
3use crate::{Exemplar, MetricNumber, ParseError, Timestamp};
4
5use super::{MetricFamilyMarshal, MetricValueMarshal};
6
7pub trait MetricsType {
8    fn can_have_exemplar(&self, metric_name: &str) -> bool;
9    fn can_have_units(&self) -> bool;
10    fn can_have_multiple_lines(&self) -> bool;
11    fn get_ignored_labels(&self, metric_name: &str) -> &[&str];
12    fn get_type_value(&self) -> MetricValueMarshal;
13}
14
15pub trait MarshalledMetricFamily {
16    type Error;
17    fn process_new_metric(
18        &mut self,
19        metric_name: &str,
20        value: MetricNumber,
21        label_names: Vec<String>,
22        label_values: Vec<String>,
23        timestamp: Option<Timestamp>,
24        exemplar: Option<Exemplar>,
25    ) -> Result<(), Self::Error>;
26
27    fn validate(&self) -> Result<(), ParseError>;
28}
29
30pub trait MarshalledMetric<T>
31where
32    T: MetricsType,
33{
34    fn validate(&self, family: &MetricFamilyMarshal<T>) -> Result<(), ParseError>;
35}
36
37pub trait RenderableMetricValue {
38    fn render(
39        &self,
40        f: &mut fmt::Formatter<'_>,
41        metric_name: &str,
42        timestamp: Option<&Timestamp>,
43        label_names: &[&str],
44        label_values: &[&str],
45    ) -> fmt::Result;
46}