-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathpair.rs
More file actions
29 lines (24 loc) · 1.04 KB
/
pair.rs
File metadata and controls
29 lines (24 loc) · 1.04 KB
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
use super::{LabelName, LabelValue};
use crate::prometheus::PrometheusSerializable;
pub type LabelPair = (LabelName, LabelValue);
// Generic implementation for any tuple (A, B) where A and B implement PrometheusSerializable
impl<A: PrometheusSerializable, B: PrometheusSerializable> PrometheusSerializable for (A, B) {
fn to_prometheus(&self) -> String {
format!("{}=\"{}\"", self.0.to_prometheus(), self.1.to_prometheus())
}
}
#[cfg(test)]
mod tests {
mod serialization_of_label_pair_to_prometheus {
use crate::label::LabelValue;
use crate::label_name;
use crate::prometheus::PrometheusSerializable;
#[test]
fn test_label_pair_serialization_to_prometheus() {
let label_pair = (label_name!("label_name"), LabelValue::new("value"));
assert_eq!(label_pair.to_prometheus(), r#"label_name="value""#);
let label_pair = (&label_name!("label_name"), &LabelValue::new("value"));
assert_eq!(label_pair.to_prometheus(), r#"label_name="value""#);
}
}
}