Skip to main content

icydb_model/node/
map.rs

1//! Module: node::map
2//! Responsibility: schema graph metadata for map collection nodes.
3//! Does not own: runtime map encoding, validation policy, or visitor execution.
4//! Boundary: stores canonical key/value descriptors for downstream schema visitors.
5
6use crate::prelude::*;
7
8///
9/// Map
10///
11/// Schema node describing a map collection with key/value descriptors and one
12/// canonical runtime type.
13///
14
15#[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    /// Creates a map node from its canonical schema parts.
26    #[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    /// Returns the definition metadata for this map node.
38    #[must_use]
39    pub const fn def(&self) -> &Def {
40        &self.def
41    }
42
43    /// Returns the current declared type name.
44    #[must_use]
45    pub const fn name(&self) -> &'static str {
46        self.name
47    }
48
49    /// Returns the key descriptor.
50    #[must_use]
51    pub const fn key(&self) -> &Item {
52        &self.key
53    }
54
55    /// Returns the value descriptor.
56    #[must_use]
57    pub const fn value(&self) -> &Value {
58        &self.value
59    }
60
61    /// Returns the canonical runtime type descriptor.
62    #[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}