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