icydb_schema/node/
type.rs1use crate::prelude::*;
2
3#[derive(Clone, Debug, Serialize)]
8pub struct Type {
9 #[serde(default, skip_serializing_if = "<[_]>::is_empty")]
10 pub sanitizers: &'static [TypeSanitizer],
11
12 #[serde(default, skip_serializing_if = "<[_]>::is_empty")]
13 pub validators: &'static [TypeValidator],
14}
15
16impl ValidateNode for Type {}
17
18impl VisitableNode for Type {
19 fn drive<V: Visitor>(&self, v: &mut V) {
20 for node in self.sanitizers {
21 node.accept(v);
22 }
23 for node in self.validators {
24 node.accept(v);
25 }
26 }
27}
28
29#[derive(Clone, Debug, Serialize)]
34pub struct TypeSanitizer {
35 pub path: &'static str,
36 pub args: Args,
37}
38
39impl ValidateNode for TypeSanitizer {
40 fn validate(&self) -> Result<(), ErrorTree> {
41 let mut errs = ErrorTree::new();
42
43 let res = schema_read().check_node_as::<Sanitizer>(self.path);
45 if let Err(e) = res {
46 errs.add(e.to_string());
47 }
48
49 errs.result()
50 }
51}
52
53impl VisitableNode for TypeSanitizer {}
54
55#[derive(Clone, Debug, Serialize)]
60pub struct TypeValidator {
61 pub path: &'static str,
62 pub args: Args,
63}
64
65impl ValidateNode for TypeValidator {
66 fn validate(&self) -> Result<(), ErrorTree> {
67 let mut errs = ErrorTree::new();
68
69 let res = schema_read().check_node_as::<Validator>(self.path);
71 if let Err(e) = res {
72 errs.add(e.to_string());
73 }
74
75 errs.result()
76 }
77}
78
79impl VisitableNode for TypeValidator {}