1mod arg;
2mod canister;
3mod def;
4mod entity;
5mod r#enum;
6mod field;
7mod index;
8mod item;
9mod list;
10mod map;
11mod memory_id;
12mod newtype;
13mod primary_key;
14mod record;
15mod sanitizer;
16mod schema;
17mod set;
18mod store;
19mod tuple;
20mod r#type;
21mod validator;
22mod value;
23
24use crate::{
25 prelude::*,
26 visit::{Event, Visitor},
27};
28use std::any::Any;
29use thiserror::Error as ThisError;
30
31pub use arg::*;
32pub use canister::*;
33pub use def::*;
34pub use entity::*;
35pub use r#enum::*;
36pub use field::*;
37pub use index::*;
38pub use item::*;
39pub use list::*;
40pub use map::*;
41pub(crate) use memory_id::{validate_memory_id_in_range, validate_memory_id_not_reserved};
42pub use newtype::*;
43pub use primary_key::*;
44pub use record::*;
45pub use sanitizer::*;
46pub use schema::*;
47pub use set::*;
48pub use store::*;
49pub use tuple::*;
50pub use r#type::*;
51pub use validator::*;
52pub use value::*;
53
54#[derive(Debug, ThisError)]
59pub enum NodeError {
60 #[error("{0} is an incorrect node type")]
61 IncorrectNodeType(String),
62
63 #[error("path not found: {0}")]
64 PathNotFound(String),
65}
66
67pub trait MacroNode: Any {
78 fn as_any(&self) -> &dyn Any;
79}
80
81pub trait TypeNode: MacroNode {
87 fn ty(&self) -> &Type;
88}
89
90pub trait ValidateNode {
95 fn validate(&self) -> Result<(), ErrorTree> {
96 Ok(())
97 }
98}
99
100pub trait VisitableNode: ValidateNode {
105 fn route_key(&self) -> String {
107 String::new()
108 }
109
110 fn accept<V: Visitor>(&self, visitor: &mut V) {
112 visitor.push(&self.route_key());
113 visitor.visit(self, Event::Enter);
114 self.drive(visitor);
115 visitor.visit(self, Event::Exit);
116 visitor.pop();
117 }
118
119 fn drive<V: Visitor>(&self, _: &mut V) {}
121}