icydb_schema/node/
mod.rs

1mod arg;
2mod canister;
3mod def;
4mod entity;
5mod r#enum;
6mod field;
7mod index;
8mod item;
9mod list;
10mod map;
11mod newtype;
12mod record;
13mod sanitizer;
14mod schema;
15mod set;
16mod store;
17mod tuple;
18mod r#type;
19mod validator;
20mod value;
21
22pub use self::arg::*;
23pub use self::canister::*;
24pub use self::def::*;
25pub use self::entity::*;
26pub use self::r#enum::*;
27pub use self::field::*;
28pub use self::index::*;
29pub use self::item::*;
30pub use self::list::*;
31pub use self::map::*;
32pub use self::newtype::*;
33pub use self::record::*;
34pub use self::sanitizer::*;
35pub use self::schema::*;
36pub use self::set::*;
37pub use self::store::*;
38pub use self::tuple::*;
39pub use self::r#type::*;
40pub use self::validator::*;
41pub use self::value::*;
42
43use crate::{
44    prelude::*,
45    visit::{Event, Visitor},
46};
47use std::any::Any;
48use thiserror::Error as ThisError;
49
50///
51/// NodeError
52///
53
54#[derive(Debug, ThisError)]
55pub enum NodeError {
56    #[error("{0} is an incorrect node type")]
57    IncorrectNodeType(String),
58
59    #[error("path not found: {0}")]
60    PathNotFound(String),
61}
62
63///
64/// NODE TRAITS
65///
66
67///
68/// MacroNode
69/// shared traits for every node that is created via a macro
70/// as_any has to be implemented on each type manually
71///
72
73pub trait MacroNode: Any {
74    fn as_any(&self) -> &dyn Any;
75}
76
77///
78/// TypeNode
79/// shared traits for every type node
80///
81
82pub trait TypeNode: MacroNode {
83    fn ty(&self) -> &Type;
84}
85
86///
87/// ValidateNode
88///
89
90pub trait ValidateNode {
91    fn validate(&self) -> Result<(), ErrorTree> {
92        Ok(())
93    }
94}
95
96///
97/// VisitableNode
98///
99
100pub trait VisitableNode: ValidateNode {
101    // route_key
102    fn route_key(&self) -> String {
103        String::new()
104    }
105
106    // accept
107    fn accept<V: Visitor>(&self, visitor: &mut V) {
108        visitor.push(&self.route_key());
109        visitor.visit(self, Event::Enter);
110        self.drive(visitor);
111        visitor.visit(self, Event::Exit);
112        visitor.pop();
113    }
114
115    // drive
116    fn drive<V: Visitor>(&self, _: &mut V) {}
117}