dir_structure_macros/
lib.rs

1use syn::ItemStruct;
2
3mod dir_structure;
4#[cfg(feature = "async")]
5mod dir_structure_async;
6mod dir_structure_core;
7
8#[proc_macro_derive(DirStructure, attributes(dir_structure))]
9pub fn derive_dir_structure(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
10    let item = syn::parse_macro_input!(item as ItemStruct);
11
12    dir_structure::expand_dir_structure(item)
13        // .map(|ts| {
14        //     eprintln!("Expanded DirStructure for {}", ts);
15        //     ts
16        // })
17        .unwrap_or_else(|err| err.to_compile_error())
18        .into()
19}
20
21#[cfg(feature = "async")]
22#[proc_macro_derive(DirStructureAsync, attributes(dir_structure))]
23pub fn derive_dir_structure_async(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
24    let item = syn::parse_macro_input!(item as ItemStruct);
25
26    dir_structure_async::expand_dir_structure_async(item)
27        // .map(|ts| {
28        //     eprintln!("Expanded DirStructureAsync for {}", ts);
29        //     ts
30        // })
31        .unwrap_or_else(|err| err.to_compile_error())
32        .into()
33}
34
35#[cfg(feature = "resolve-path")]
36mod resolve_path;
37
38#[cfg(feature = "resolve-path")]
39#[proc_macro]
40pub fn resolve_path(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
41    resolve_path::resolve_path(input)
42}
43
44#[cfg(feature = "resolve-path")]
45#[proc_macro]
46pub fn load_path(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
47    resolve_path::load_path(input)
48}
49
50#[cfg(feature = "resolve-path")]
51#[proc_macro]
52pub fn __resolve_max_len(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
53    // This macro is used to get the maximum length of a field name for the `HasField` trait.
54    // It is used in the `resolve_path` macro to ensure that field names do not exceed this length.
55    let max_len = resolve_path::MAX_LEN;
56    let output = quote::quote! { #max_len };
57    output.into()
58}