1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// use std::any::Any;
// use std::fmt;
// use std::collections::HashMap;
// use serde::{Serializer, Deserializer, Serialize, Deserialize};
// use serde::ser::SerializeMap;
// use serde::de::{MapAccess, Visitor};
// use std::marker::PhantomData;
//
// /// Enum representing either a single string or a vector of strings.
// #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
// pub enum AttributeValue {
// Single(String),
// Multiple(Vec<String>),
// }
//
// /// A collection of key-value pairs, often used for metadata or additional attributes.
// #[derive(Clone, Debug, Default, PartialEq, Eq)]
// pub struct Attributes {
// inner: HashMap<String, AttributeValue>,
// }
//
// impl Attributes {
// /// Creates a new, empty `Attributes` instance.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::Attributes;
// /// let attributes = Attributes::new();
// /// assert!(attributes.is_empty());
// /// ```
// pub fn new() -> Self {
// Self {
// inner: HashMap::new(),
// }
// }
//
// /// Inserts a key-value pair into the attributes.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// assert_eq!(attributes.get("key1"), Some(&AttributeValue::Single("value1".to_string())));
// /// ```
// pub fn insert(&mut self, key: impl Into<String>, value: impl Into<AttributeValue>) -> Option<AttributeValue> {
// self.inner.insert(key.into(), value.into())
// }
//
// /// Gets a reference to the value corresponding to the key.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// assert_eq!(attributes.get("key1"), Some(&AttributeValue::Single("value1".to_string())));
// /// assert_eq!(attributes.get("key2"), None);
// /// ```
// pub fn get(&self, key: &str) -> Option<&AttributeValue> {
// self.inner.get(key)
// }
//
// /// Removes a key-value pair from the attributes.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// assert_eq!(attributes.remove("key1"), Some(AttributeValue::Single("value1".to_string())));
// /// assert!(attributes.get("key1").is_none());
// /// ```
// pub fn remove(&mut self, key: &str) -> Option<AttributeValue> {
// self.inner.remove(key)
// }
//
// /// Checks if the attributes contain a key.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// assert!(attributes.contains_key("key1"));
// /// assert!(!attributes.contains_key("key2"));
// /// ```
// pub fn contains_key(&self, key: &str) -> bool {
// self.inner.contains_key(key)
// }
//
// /// Returns the number of key-value pairs in the attributes.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// assert_eq!(attributes.len(), 1);
// /// ```
// pub fn len(&self) -> usize {
// self.inner.len()
// }
//
// /// Returns true if the attributes contain no key-value pairs.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::Attributes;
// /// let attributes = Attributes::new();
// /// assert!(attributes.is_empty());
// /// ```
// pub fn is_empty(&self) -> bool {
// self.inner.is_empty()
// }
//
// /// Clears all key-value pairs from the attributes.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// attributes.clear();
// /// assert!(attributes.is_empty());
// /// ```
// pub fn clear(&mut self) {
// self.inner.clear()
// }
//
// /// Returns an iterator over the key-value pairs.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// for (key, value) in attributes.iter() {
// /// println!("{}: {:?}", key, value);
// /// }
// /// ```
// pub fn iter(&self) -> impl Iterator<Item=(&String, &AttributeValue)> {
// self.inner.iter()
// }
//
// /// Merges another `Attributes` into this one, overwriting existing keys.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes1 = Attributes::new();
// /// attributes1.insert("key1", AttributeValue::Single("value1".to_string()));
// ///
// /// let mut attributes2 = Attributes::new();
// /// attributes2.insert("key2", AttributeValue::Single("value2".to_string()));
// ///
// /// attributes1.merge(attributes2);
// /// assert_eq!(attributes1.get("key2"), Some(&AttributeValue::Single("value2".to_string())));
// /// ```
// pub fn merge(&mut self, other: Attributes) {
// self.inner.extend(other.inner);
// }
// }
//
// impl Serialize for Attributes {
// /// Serializes the `Attributes` into the given serializer.
// ///
// /// # Arguments
// ///
// /// * `serializer` - The serializer to use for serialization.
// ///
// /// # Returns
// ///
// /// A result containing either the serialized value or an error.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// let serialized = serde_json::to_string(&attributes).unwrap();
// /// ```
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let mut map = serializer.serialize_map(Some(self.inner.len()))?;
// for (k, v) in &self.inner {
// map.serialize_entry(k, v)?;
// }
// map.end()
// }
// }
//
// impl<'de> Deserialize<'de> for Attributes {
// /// Deserializes the `Attributes` from the given deserializer.
// ///
// /// # Arguments
// ///
// /// * `deserializer` - The deserializer to use for deserialization.
// ///
// /// # Returns
// ///
// /// A result containing either the deserialized `Attributes` or an error.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::Attributes;
// /// let json = r#"{"key1":"value1"}"#;
// /// let attributes: Attributes = serde_json::from_str(json).unwrap();
// /// ```
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
// where
// D: Deserializer<'de>,
// {
// struct AttributesVisitor {
// marker: PhantomData<fn() -> Attributes>,
// }
//
// impl<'de> Visitor<'de> for AttributesVisitor {
// type Value = Attributes;
//
// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
// formatter.write_str("a map of strings to AttributeValue")
// }
//
// fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
// where
// M: MapAccess<'de>,
// {
// let mut map = HashMap::new();
// while let Some((key, value)) = access.next_entry()? {
// map.insert(key, value);
// }
// Ok(Attributes { inner: map })
// }
// }
//
// deserializer.deserialize_map(AttributesVisitor { marker: PhantomData })
// }
// }
//
// impl fmt::Display for Attributes {
// /// Formats the `Attributes` for display.
// ///
// /// # Arguments
// ///
// /// * `f` - The formatter to use for formatting.
// ///
// /// # Returns
// ///
// /// A result containing either the formatted string or an error.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Attributes, AttributeValue};
// /// let mut attributes = Attributes::new();
// /// attributes.insert("key1", AttributeValue::Single("value1".to_string()));
// /// println!("{}", attributes);
// /// ```
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// write!(f, "{{ ")?;
// for (key, value) in &self.inner {
// write!(f, "{}: {:?}, ", key, value)?;
// }
// write!(f, "}}")
// }
// }
//
// /// Represents a key-value pair with additional attributes.
// #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
// pub struct Key {
// pub name: String,
// pub value: String,
// pub attributes: Attributes,
// }
//
// impl Key {
// /// Creates a new `Key` instance.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Key, Attributes};
// /// let attributes = Attributes::new();
// /// let key = Key::new("name", "value", attributes);
// /// assert_eq!(key.name, "name");
// /// assert_eq!(key.value, "value");
// /// ```
// pub fn new(name: impl Into<String>, value: impl Into<String>, attributes: Attributes) -> Self {
// Self {
// name: name.into(),
// value: value.into(),
// attributes,
// }
// }
//
// /// Converts the `Key` into a dynamic reference.
// ///
// /// # Examples
// ///
// /// ```
// /// use keyflux::key::{Key, Attributes};
// /// let attributes = Attributes::new();
// /// let key = Key::new("name", "value", attributes);
// /// let any_key = key.as_any();
// /// ```
// pub fn as_any(&self) -> &dyn Any {
// self
// }
// }