Skip to main content

icydb_schema/node/
set.rs

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