Skip to main content

torrust_metrics/label/
pair.rs

1use super::{LabelName, LabelValue};
2use crate::prometheus::PrometheusSerializable;
3
4pub type LabelPair = (LabelName, LabelValue);
5
6// Generic implementation for any tuple (A, B) where A and B implement PrometheusSerializable
7impl<A: PrometheusSerializable, B: PrometheusSerializable> PrometheusSerializable for (A, B) {
8    fn to_prometheus(&self) -> String {
9        format!("{}=\"{}\"", self.0.to_prometheus(), self.1.to_prometheus())
10    }
11}
12
13#[cfg(test)]
14mod tests {
15    mod serialization_of_label_pair_to_prometheus {
16        use crate::label::LabelValue;
17        use crate::label_name;
18        use crate::prometheus::PrometheusSerializable;
19
20        #[test]
21        fn test_label_pair_serialization_to_prometheus() {
22            let label_pair = (label_name!("label_name"), LabelValue::new("value"));
23            assert_eq!(label_pair.to_prometheus(), r#"label_name="value""#);
24
25            let label_pair = (&label_name!("label_name"), &LabelValue::new("value"));
26            assert_eq!(label_pair.to_prometheus(), r#"label_name="value""#);
27        }
28    }
29}