Skip to main content

icydb_schema/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    key: Item,
19    value: Value,
20    ty: Type,
21}
22
23impl Map {
24    /// Creates a map node from its canonical schema parts.
25    #[must_use]
26    pub const fn new(def: Def, key: Item, value: Value, ty: Type) -> Self {
27        Self {
28            def,
29            key,
30            value,
31            ty,
32        }
33    }
34
35    /// Returns the definition metadata for this map node.
36    #[must_use]
37    pub const fn def(&self) -> &Def {
38        &self.def
39    }
40
41    /// Returns the key descriptor.
42    #[must_use]
43    pub const fn key(&self) -> &Item {
44        &self.key
45    }
46
47    /// Returns the value descriptor.
48    #[must_use]
49    pub const fn value(&self) -> &Value {
50        &self.value
51    }
52
53    /// Returns the canonical runtime type descriptor.
54    #[must_use]
55    pub const fn ty(&self) -> &Type {
56        &self.ty
57    }
58}
59
60impl MacroNode for Map {
61    fn as_any(&self) -> &dyn std::any::Any {
62        self
63    }
64}
65
66impl ValidateNode for Map {}
67
68impl VisitableNode for Map {
69    fn route_key(&self) -> String {
70        self.def().path()
71    }
72
73    fn drive<V: Visitor>(&self, v: &mut V) {
74        self.def().accept(v);
75        self.key().accept(v);
76        self.value().accept(v);
77        self.ty().accept(v);
78    }
79}