icydb_model/node/
tuple.rs1use crate::prelude::*;
2
3#[derive(Clone, Debug, Serialize)]
8pub struct Tuple {
9 def: Def,
10 source_key: &'static str,
11 values: &'static [Value],
12 ty: Type,
13}
14
15impl Tuple {
16 #[must_use]
18 pub const fn new(
19 def: Def,
20 source_key: &'static str,
21 values: &'static [Value],
22 ty: Type,
23 ) -> Self {
24 Self {
25 def,
26 source_key,
27 values,
28 ty,
29 }
30 }
31
32 #[must_use]
34 pub const fn def(&self) -> &Def {
35 &self.def
36 }
37
38 #[must_use]
40 pub const fn source_key(&self) -> &'static str {
41 self.source_key
42 }
43
44 #[must_use]
46 pub const fn values(&self) -> &'static [Value] {
47 self.values
48 }
49
50 #[must_use]
52 pub const fn ty(&self) -> &Type {
53 &self.ty
54 }
55}
56
57impl MacroNode for Tuple {
58 fn as_any(&self) -> &dyn std::any::Any {
59 self
60 }
61}
62
63impl ValidateNode for Tuple {
64 fn validate(&self) -> Result<(), ErrorTree> {
65 let mut errs = ErrorTree::new();
66 validate_source_key(
67 &mut errs,
68 "tuple type",
69 self.source_key(),
70 icydb_schema::TypeSourceKey::try_new,
71 );
72 errs.result()
73 }
74}
75
76impl VisitableNode for Tuple {
77 fn route_key(&self) -> String {
78 self.def().path()
79 }
80
81 fn drive<V: Visitor>(&self, v: &mut V) {
82 self.def().accept(v);
83 for node in self.values() {
84 node.accept(v);
85 }
86 self.ty().accept(v);
87 }
88}