easy_macros/lib.rs
1// Compile README.docify.md to README.md
2#[cfg(feature = "generate-readme")]
3docify::compile_markdown!("README.docify.md", "README.md");
4
5#[cfg(feature = "all-syntax-cases")]
6pub use all_syntax_cases::*;
7
8#[cfg(feature = "always-context")]
9pub use always_context::*;
10
11#[cfg(feature = "build")]
12pub use always_context_build;
13
14#[cfg(feature = "anyhow-result")]
15/// Enables procedural macros to return `anyhow::Result<TokenStream>` for ergonomic error handling.
16///
17/// This attribute wraps proc-macro functions to automatically handle `anyhow::Result` return types,
18/// converting errors into appropriate `compile_error!` tokens.
19///
20/// # Usage
21///
22/// ```rust,ignore
23/// use anyhow::Context;
24/// use proc_macro::TokenStream;
25///
26/// #[proc_macro]
27/// #[anyhow_result]
28/// pub fn my_macro(input: TokenStream) -> anyhow::Result<TokenStream> {
29/// let parsed: syn::ItemStruct = syn::parse(input)
30/// .context("Expected a struct definition")?;
31///
32/// // Your macro logic here
33/// Ok(quote! { /* generated code */ }.into())
34/// }
35/// ```
36///
37/// # Error Handling
38///
39/// When your function returns an `Err`, `anyhow_result` automatically converts it:
40/// - **`#[proc_macro]` and `#[proc_macro_derive]`**: Returns `compile_error!` with the error message
41/// - **`#[proc_macro_attribute]`**: Returns `compile_error!` followed by the original input item
42///
43/// # See Also
44///
45/// - [`anyhow`](https://docs.rs/anyhow/) - Error handling library
46/// - [`syn`](https://docs.rs/syn/) - Rust code parsing
47/// - [`quote`](https://docs.rs/quote/) - Code generation
48pub use anyhow_result::anyhow_result;
49
50#[cfg(feature = "attributes")]
51pub use attributes::{
52 AttrWithUnknown, fields_get_attributes, fields_with_attributes, get_attributes, has_attributes,
53};
54
55// === Helper Function Exports ===
56
57/// Helper utilities for building procedural macros
58#[cfg(feature = "helpers-dont-use-directly-this-feature")]
59pub use helpers::*;
60
61#[cfg(test)]
62mod macro_tests;
63
64#[cfg(test)]
65mod examples;