1use crate::prelude::*;
7
8#[derive(Clone, Debug, Serialize)]
16pub struct Map {
17 def: Def,
18 source_key: &'static str,
19 key: Item,
20 value: Value,
21 ty: Type,
22}
23
24impl Map {
25 #[must_use]
27 pub const fn new(
28 def: Def,
29 source_key: &'static str,
30 key: Item,
31 value: Value,
32 ty: Type,
33 ) -> Self {
34 Self {
35 def,
36 source_key,
37 key,
38 value,
39 ty,
40 }
41 }
42
43 #[must_use]
45 pub const fn def(&self) -> &Def {
46 &self.def
47 }
48
49 #[must_use]
51 pub const fn source_key(&self) -> &'static str {
52 self.source_key
53 }
54
55 #[must_use]
57 pub const fn key(&self) -> &Item {
58 &self.key
59 }
60
61 #[must_use]
63 pub const fn value(&self) -> &Value {
64 &self.value
65 }
66
67 #[must_use]
69 pub const fn ty(&self) -> &Type {
70 &self.ty
71 }
72}
73
74impl MacroNode for Map {
75 fn as_any(&self) -> &dyn std::any::Any {
76 self
77 }
78}
79
80impl ValidateNode for Map {
81 fn validate(&self) -> Result<(), ErrorTree> {
82 let mut errs = ErrorTree::new();
83 validate_source_key(
84 &mut errs,
85 "map type",
86 self.source_key(),
87 icydb_schema::TypeSourceKey::try_new,
88 );
89 errs.result()
90 }
91}
92
93impl VisitableNode for Map {
94 fn route_key(&self) -> String {
95 self.def().path()
96 }
97
98 fn drive<V: Visitor>(&self, v: &mut V) {
99 self.def().accept(v);
100 self.key().accept(v);
101 self.value().accept(v);
102 self.ty().accept(v);
103 }
104}