pipeline/etl/value/
map.rs1use std::collections::BTreeMap;
16
17use crate::etl::value::Value;
18
19#[derive(Debug, Clone, PartialEq, Default)]
20pub struct Map {
21 pub values: BTreeMap<String, Value>,
22}
23
24impl Map {
25 pub fn one(key: impl Into<String>, value: Value) -> Map {
26 let mut map = Map::default();
27 map.insert(key, value);
28 map
29 }
30
31 pub fn insert(&mut self, key: impl Into<String>, value: Value) {
32 self.values.insert(key.into(), value);
33 }
34
35 pub fn extend(&mut self, Map { values }: Map) {
36 self.values.extend(values);
37 }
38}
39
40impl From<BTreeMap<String, Value>> for Map {
41 fn from(values: BTreeMap<String, Value>) -> Self {
42 Self { values }
43 }
44}
45
46impl std::ops::Deref for Map {
47 type Target = BTreeMap<String, Value>;
48
49 fn deref(&self) -> &Self::Target {
50 &self.values
51 }
52}
53
54impl std::ops::DerefMut for Map {
55 fn deref_mut(&mut self) -> &mut Self::Target {
56 &mut self.values
57 }
58}
59
60impl std::fmt::Display for Map {
61 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
62 let values = self
63 .values
64 .iter()
65 .map(|(k, v)| format!("{}: {}", k, v))
66 .collect::<Vec<String>>()
67 .join(", ");
68 write!(f, "{{{}}}", values)
69 }
70}