Skip to main content

icydb_model/node/
tuple.rs

1use crate::prelude::*;
2
3///
4/// Tuple
5///
6
7#[derive(Clone, Debug, Serialize)]
8pub struct Tuple {
9    def: Def,
10    name: &'static str,
11    values: &'static [Value],
12    ty: Type,
13}
14
15impl Tuple {
16    /// Creates a tuple node from its canonical schema parts.
17    #[must_use]
18    pub const fn new(def: Def, name: &'static str, values: &'static [Value], ty: Type) -> Self {
19        Self {
20            def,
21            name,
22            values,
23            ty,
24        }
25    }
26
27    /// Returns the definition metadata for this tuple node.
28    #[must_use]
29    pub const fn def(&self) -> &Def {
30        &self.def
31    }
32
33    /// Returns the current declared type name.
34    #[must_use]
35    pub const fn name(&self) -> &'static str {
36        self.name
37    }
38
39    /// Returns the tuple value descriptors.
40    #[must_use]
41    pub const fn values(&self) -> &'static [Value] {
42        self.values
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 Tuple {
53    fn as_any(&self) -> &dyn std::any::Any {
54        self
55    }
56}
57
58impl ValidateNode for Tuple {
59    fn validate(&self) -> Result<(), ErrorTree> {
60        let mut errs = ErrorTree::new();
61        validate_source_name(
62            &mut errs,
63            "tuple type",
64            self.name(),
65            icydb_schema::TypeSourceKey::try_new,
66        );
67        errs.result()
68    }
69}
70
71impl VisitableNode for Tuple {
72    fn route_key(&self) -> String {
73        self.def().path()
74    }
75
76    fn drive<V: Visitor>(&self, v: &mut V) {
77        self.def().accept(v);
78        for node in self.values() {
79            node.accept(v);
80        }
81        self.ty().accept(v);
82    }
83}