qubit_progress/
operation_attributes.rs1use std::collections::BTreeMap;
11use std::sync::Arc;
12
13#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
15#[cfg_attr(feature = "serde", serde(transparent))]
16#[derive(Clone, Debug, Default, Eq, PartialEq)]
17pub struct OperationAttributes {
18 entries: BTreeMap<Arc<str>, Arc<str>>,
20}
21
22impl OperationAttributes {
23 #[must_use]
25 pub fn new() -> Self {
26 Self::default()
27 }
28
29 pub fn insert(&mut self, key: &str, value: &str) {
31 self.entries.insert(Arc::from(key), Arc::from(value));
32 }
33
34 #[must_use]
36 pub fn get(&self, key: &str) -> Option<&str> {
37 self.entries.get(key).map(AsRef::as_ref)
38 }
39
40 #[must_use = "the iterator yields configured attributes"]
42 pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> + '_ {
43 self.entries
44 .iter()
45 .map(|(key, value)| (key.as_ref(), value.as_ref()))
46 }
47
48 #[must_use]
50 pub fn is_empty(&self) -> bool {
51 self.entries.is_empty()
52 }
53}