icydb_schema/node/
enum.rs1use crate::prelude::*;
2use std::ops::Not;
3
4#[derive(Clone, Debug, Serialize)]
9pub struct Enum {
10 pub def: Def,
11 pub variants: &'static [EnumVariant],
12 pub ty: Type,
13}
14
15impl MacroNode for Enum {
16 fn as_any(&self) -> &dyn std::any::Any {
17 self
18 }
19}
20
21impl TypeNode for Enum {
22 fn ty(&self) -> &Type {
23 &self.ty
24 }
25}
26
27impl ValidateNode for Enum {
28 fn validate(&self) -> Result<(), ErrorTree> {
29 Ok(())
30 }
31}
32
33impl VisitableNode for Enum {
34 fn route_key(&self) -> String {
35 self.def.path()
36 }
37
38 fn drive<V: Visitor>(&self, v: &mut V) {
39 self.def.accept(v);
40 for node in self.variants {
41 node.accept(v);
42 }
43 self.ty.accept(v);
44 }
45}
46
47#[derive(Clone, Debug, Serialize)]
52pub struct EnumVariant {
53 pub ident: &'static str,
54
55 #[serde(default, skip_serializing_if = "Option::is_none")]
56 pub value: Option<Value>,
57
58 #[serde(default, skip_serializing_if = "Not::not")]
59 pub default: bool,
60
61 #[serde(default, skip_serializing_if = "Not::not")]
62 pub unspecified: bool,
63}
64
65impl ValidateNode for EnumVariant {
66 fn validate(&self) -> Result<(), ErrorTree> {
67 Ok(())
68 }
69}
70
71impl VisitableNode for EnumVariant {
72 fn drive<V: Visitor>(&self, v: &mut V) {
73 if let Some(node) = &self.value {
74 node.accept(v);
75 }
76 }
77}