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