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#[derive(Debug, ThisError)]
55pub enum NodeError {
56 #[error("error downcasting schema node: {0}")]
57 DowncastFail(String),
58
59 #[error("{0} is an incorrect node type")]
60 IncorrectNodeType(String),
61
62 #[error("path not found: {0}")]
63 PathNotFound(String),
64}
65
66pub trait MacroNode: Any {
77 fn as_any(&self) -> &dyn Any;
78}
79
80pub trait TypeNode: MacroNode {
86 fn ty(&self) -> &Type;
87}
88
89pub trait ValidateNode {
94 fn validate(&self) -> Result<(), ErrorTree> {
95 Ok(())
96 }
97}
98
99pub trait VisitableNode: ValidateNode {
104 fn route_key(&self) -> String {
106 String::new()
107 }
108
109 fn accept<V: Visitor>(&self, visitor: &mut V) {
111 visitor.push(&self.route_key());
112 visitor.visit(self, Event::Enter);
113 self.drive(visitor);
114 visitor.visit(self, Event::Exit);
115 visitor.pop();
116 }
117
118 fn drive<V: Visitor>(&self, _: &mut V) {}
120}