Skip to main content

icydb_schema/node/
map.rs

1use crate::prelude::*;
2
3///
4/// Map
5///
6
7#[derive(Clone, Debug, Serialize)]
8pub struct Map {
9    def: Def,
10    key: Item,
11    value: Value,
12    ty: Type,
13}
14
15impl Map {
16    /// Creates a map node from its canonical schema parts.
17    #[must_use]
18    pub const fn new(def: Def, key: Item, value: Value, ty: Type) -> Self {
19        Self {
20            def,
21            key,
22            value,
23            ty,
24        }
25    }
26
27    /// Returns the definition metadata for this map node.
28    #[must_use]
29    pub const fn def(&self) -> &Def {
30        &self.def
31    }
32
33    /// Returns the key descriptor.
34    #[must_use]
35    pub const fn key(&self) -> &Item {
36        &self.key
37    }
38
39    /// Returns the value descriptor.
40    #[must_use]
41    pub const fn value(&self) -> &Value {
42        &self.value
43    }
44
45    /// Returns the canonical runtime type descriptor.
46    #[must_use]
47    pub const fn ty(&self) -> &Type {
48        &self.ty
49    }
50}
51
52impl MacroNode for Map {
53    fn as_any(&self) -> &dyn std::any::Any {
54        self
55    }
56}
57
58impl TypeNode for Map {
59    fn ty(&self) -> &Type {
60        self.ty()
61    }
62}
63
64impl ValidateNode for Map {}
65
66impl VisitableNode for Map {
67    fn route_key(&self) -> String {
68        self.def().path()
69    }
70
71    fn drive<V: Visitor>(&self, v: &mut V) {
72        self.def().accept(v);
73        self.key().accept(v);
74        self.value().accept(v);
75        self.ty().accept(v);
76    }
77}