Skip to main content

icydb_model/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    name: &'static str,
14    item: Item,
15    ty: Type,
16}
17
18impl Set {
19    /// Creates a set node from its canonical schema parts.
20    #[must_use]
21    pub const fn new(def: Def, name: &'static str, item: Item, ty: Type) -> Self {
22        Self {
23            def,
24            name,
25            item,
26            ty,
27        }
28    }
29
30    /// Returns the definition metadata for this set node.
31    #[must_use]
32    pub const fn def(&self) -> &Def {
33        &self.def
34    }
35
36    /// Returns the current declared type name.
37    #[must_use]
38    pub const fn name(&self) -> &'static str {
39        self.name
40    }
41
42    /// Returns the set item descriptor.
43    #[must_use]
44    pub const fn item(&self) -> &Item {
45        &self.item
46    }
47
48    /// Returns the canonical runtime type descriptor.
49    #[must_use]
50    pub const fn ty(&self) -> &Type {
51        &self.ty
52    }
53}
54
55impl MacroNode for Set {
56    fn as_any(&self) -> &dyn std::any::Any {
57        self
58    }
59}
60
61impl ValidateNode for Set {
62    fn validate(&self) -> Result<(), ErrorTree> {
63        let mut errs = ErrorTree::new();
64        validate_source_name(
65            &mut errs,
66            "set type",
67            self.name(),
68            icydb_schema::TypeSourceKey::try_new,
69        );
70        self.item().validate_immutable_key_hooks(&mut errs);
71        errs.result()
72    }
73}
74
75impl VisitableNode for Set {
76    fn route_key(&self) -> String {
77        self.def().path()
78    }
79
80    fn drive<V: Visitor>(&self, v: &mut V) {
81        self.def().accept(v);
82        self.item().accept(v);
83        self.ty().accept(v);
84    }
85}