entity_macros/derive/ent/
mod.rs

1mod r#enum;
2mod r#struct;
3
4use darling::FromDeriveInput;
5use entity_macros_data::{EnumEnt, StructEnt};
6use proc_macro2::TokenStream;
7use syn::{Data, DeriveInput, Path};
8
9pub fn do_derive_ent(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
10    match &input.data {
11        Data::Struct(_) => r#struct::do_derive_ent(root, StructEnt::from_derive_input(&input)?),
12        Data::Enum(_) => r#enum::do_derive_ent(root, EnumEnt::from_derive_input(&input)?),
13        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
14    }
15}
16
17pub fn do_derive_ent_wrapper(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
18    match &input.data {
19        Data::Struct(_) => {
20            Err(darling::Error::custom("Structs are not supported").with_span(&input))
21        }
22        Data::Enum(_) => Ok(r#enum::do_derive_ent_wrapper(
23            root,
24            EnumEnt::from_derive_input(&input)?,
25        )),
26        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
27    }
28}
29
30pub fn do_derive_ent_builder(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
31    match &input.data {
32        Data::Struct(_) => Ok(r#struct::do_derive_ent_builder(
33            root,
34            StructEnt::from_derive_input(&input)?,
35        )),
36        Data::Enum(_) => Err(darling::Error::custom("Enums are not supported").with_span(&input)),
37        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
38    }
39}
40
41pub fn do_derive_ent_loader(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
42    match &input.data {
43        Data::Struct(_) => Ok(r#struct::do_derive_ent_loader(
44            root,
45            StructEnt::from_derive_input(&input)?,
46        )),
47        Data::Enum(_) => Err(darling::Error::custom("Enums are not supported").with_span(&input)),
48        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
49    }
50}
51
52pub fn do_derive_ent_debug(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
53    match &input.data {
54        Data::Struct(_) => Ok(r#struct::do_derive_ent_debug(
55            root,
56            StructEnt::from_derive_input(&input)?,
57        )),
58        Data::Enum(_) => Err(darling::Error::custom(
59            "Enums are not supported, derive Debug instead",
60        )
61        .with_span(&input)),
62        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
63    }
64}
65
66pub fn do_derive_ent_query(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
67    match &input.data {
68        Data::Struct(_) => {
69            r#struct::do_derive_ent_query(root, StructEnt::from_derive_input(&input)?)
70        }
71        Data::Enum(_) => Ok(r#enum::do_derive_ent_query(
72            root,
73            EnumEnt::from_derive_input(&input)?,
74        )),
75        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
76    }
77}
78
79pub fn do_derive_ent_type(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
80    match &input.data {
81        Data::Struct(_) => Ok(r#struct::do_derive_ent_type(
82            root,
83            StructEnt::from_derive_input(&input)?,
84        )),
85        Data::Enum(_) => Ok(r#enum::do_derive_ent_type(
86            root,
87            EnumEnt::from_derive_input(&input)?,
88        )),
89        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
90    }
91}
92
93pub fn do_derive_ent_typed_edges(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
94    match &input.data {
95        Data::Struct(_) => Ok(r#struct::do_derive_ent_typed_edges(
96            root,
97            StructEnt::from_derive_input(&input)?,
98        )),
99        Data::Enum(_) => Err(darling::Error::custom("Enums are not supported").with_span(&input)),
100        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
101    }
102}
103
104pub fn do_derive_ent_typed_fields(root: Path, input: DeriveInput) -> darling::Result<TokenStream> {
105    match &input.data {
106        Data::Struct(_) => Ok(r#struct::do_derive_ent_typed_fields(
107            root,
108            StructEnt::from_derive_input(&input)?,
109        )),
110        Data::Enum(_) => Err(darling::Error::custom("Enums are not supported").with_span(&input)),
111        Data::Union(_) => Err(darling::Error::custom("Unions are not supported").with_span(&input)),
112    }
113}