lib.rs 836 B

1234567891011121314151617181920212223242526272829303132
  1. extern crate proc_macro;
  2. /// A marker attribute used to mark const values that should be included in the
  3. /// generated IDL but functionally does nothing.
  4. #[proc_macro_attribute]
  5. pub fn constant(
  6. _attr: proc_macro::TokenStream,
  7. input: proc_macro::TokenStream,
  8. ) -> proc_macro::TokenStream {
  9. #[cfg(feature = "idl-build")]
  10. {
  11. use quote::quote;
  12. let ts = match syn::parse(input).unwrap() {
  13. syn::Item::Const(item) => {
  14. let idl_print = anchor_syn::idl::gen_idl_print_fn_constant(&item);
  15. quote! {
  16. #item
  17. #idl_print
  18. }
  19. }
  20. item => quote! {#item},
  21. };
  22. return proc_macro::TokenStream::from(quote! {
  23. #ts
  24. });
  25. };
  26. #[allow(unreachable_code)]
  27. input
  28. }