1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extern crate proc_macro;

/// A marker attribute used to mark const values that should be included in the
/// generated IDL but functionally does nothing.
#[proc_macro_attribute]
pub fn constant(
    _attr: proc_macro::TokenStream,
    input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    #[cfg(feature = "idl-build")]
    {
        use quote::quote;

        let ts = match syn::parse(input).unwrap() {
            syn::Item::Const(item) => {
                let idl_print = anchor_syn::idl::gen_idl_print_fn_constant(&item);
                quote! {
                    #item
                    #idl_print
                }
            }
            item => quote! {#item},
        };

        return proc_macro::TokenStream::from(quote! {
            #ts
        });
    };

    #[allow(unreachable_code)]
    input
}