use std::collections::BTreeMap;
use std::sync::Arc;
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct OperationAttributes {
entries: BTreeMap<Arc<str>, Arc<str>>,
}
impl OperationAttributes {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn insert(&mut self, key: &str, value: &str) {
self.entries.insert(Arc::from(key), Arc::from(value));
}
#[must_use]
pub fn get(&self, key: &str) -> Option<&str> {
self.entries.get(key).map(AsRef::as_ref)
}
#[must_use = "the iterator yields configured attributes"]
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> + '_ {
self.entries
.iter()
.map(|(key, value)| (key.as_ref(), value.as_ref()))
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}