Skip to main content

icydb_schema/node/
field.rs

1use crate::prelude::*;
2
3///
4/// FieldList
5///
6
7#[derive(Clone, Debug, Serialize)]
8pub struct FieldList {
9    pub fields: &'static [Field],
10}
11
12impl FieldList {
13    // get
14    #[must_use]
15    pub fn get(&self, ident: &str) -> Option<&Field> {
16        self.fields.iter().find(|f| f.ident == ident)
17    }
18}
19
20impl ValidateNode for FieldList {}
21
22impl VisitableNode for FieldList {
23    fn drive<V: Visitor>(&self, v: &mut V) {
24        for node in self.fields {
25            node.accept(v);
26        }
27    }
28}
29
30///
31/// Field
32///
33
34#[derive(Clone, Debug, Serialize)]
35pub struct Field {
36    pub ident: &'static str,
37    pub value: Value,
38
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub default: Option<Arg>,
41}
42
43impl ValidateNode for Field {
44    fn validate(&self) -> Result<(), ErrorTree> {
45        Ok(())
46    }
47}
48
49impl VisitableNode for Field {
50    fn route_key(&self) -> String {
51        self.ident.to_string()
52    }
53
54    fn drive<V: Visitor>(&self, v: &mut V) {
55        self.value.accept(v);
56        if let Some(node) = &self.default {
57            node.accept(v);
58        }
59    }
60}