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