#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Labels(Vec<(String, String)>);
impl Labels {
#[must_use]
pub fn new() -> Self { Self::default() }
#[must_use]
pub fn with(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.0.push((key.into(), value.into()));
self
}
pub(crate) fn as_str_pairs(&self) -> Vec<(&str, &str)> {
self.0
.iter()
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect()
}
}
impl From<&[(&str, &str)]> for Labels {
fn from(pairs: &[(&str, &str)]) -> Self {
Self(
pairs
.iter()
.map(|(k, v)| ((*k).to_owned(), (*v).to_owned()))
.collect(),
)
}
}
impl<const N: usize> From<[(&str, &str); N]> for Labels {
fn from(pairs: [(&str, &str); N]) -> Self {
Self(
pairs
.into_iter()
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect(),
)
}
}
impl<const N: usize> From<&[(&str, &str); N]> for Labels {
fn from(pairs: &[(&str, &str); N]) -> Self {
Self(
pairs
.iter()
.map(|(k, v)| ((*k).to_owned(), (*v).to_owned()))
.collect(),
)
}
}