Skip to main content

icydb_schema/node/
mod.rs

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