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