diff --git a/metrics/src/label.rs b/metrics/src/label.rs index 4e04cbce..b649e894 100644 --- a/metrics/src/label.rs +++ b/metrics/src/label.rs @@ -56,6 +56,16 @@ where } } +impl From<(&K, &V)> for Label +where + K: Into + Clone, + V: Into + Clone, +{ + fn from(pair: (&K, &V)) -> Label { + Label::new(pair.0.clone(), pair.1.clone()) + } +} + /// A value that can be converted to a vector of [`Label`]s. pub trait IntoLabels { /// Consumes this value, turning it into a vector of [`Label`]s. @@ -99,4 +109,14 @@ mod label_tests { let expected = vec![Label::new("x", "a"), Label::new("y", "b")]; assert_eq!(from_slice_to_labels(&labels), expected); } + + #[test] + fn btreemap_to_labels() { + use std::collections::BTreeMap; + + let labels_btreemap = BTreeMap::from([("customer", "Rust Foundation")]); + + let expected = vec![Label::new("customer", "Rust Foundation")]; + assert_eq!(labels_btreemap.into_labels(), expected); + } }