use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SharedLabel {
key: String,
value: String,
}
impl SharedLabel {
pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
Self {
key: key.into(),
value: value.into(),
}
}
pub fn key(&self) -> &str {
&self.key
}
pub fn value(&self) -> &str {
&self.value
}
}
impl fmt::Display for SharedLabel {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}={}", self.key, self.value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_label_reads_as_key_equals_value() {
assert_eq!(
SharedLabel::new("incident", "north-outage").to_string(),
"incident=north-outage"
);
}
#[test]
fn the_same_value_under_two_kinds_is_two_labels() {
assert_ne!(
SharedLabel::new("owner", "kmp"),
SharedLabel::new("repo", "kmp")
);
}
}