xmacro 0.1.1

rust macro producing multiple expansions
Documentation
#![doc = include_str!("../README.md")]
use proc_macro::TokenStream;
use xmacro_lib::{ xmacro_expand, xmacro_expand_items};

/// Generate code by expanding template expressions with substitutions.
///
/// The `xmacro!` macro allows you to define code templates with substitution points
/// and expand them using sets of values. It supports:
///
/// - Named and unnamed definitions
/// - Nested scopes with `${...}`
/// - Single item  expansions with `$(...)`
/// - Vertical table-based expansions with `$[...]`
/// - Each-by-each or row-wise expansion modes
///
/// # Example
/// ```rust
/// # use xmacro::xmacro;
/// struct Container<T>(T);
/// trait Trait {}
/// xmacro! {
///     // Define types to substitute
///     $(T: (i32)(u32)(f64))
///
///     // Generate implementations
///     impl Trait for Container<$T> {}
/// }
/// ```
#[allow(clippy::missing_panics_doc)]
#[proc_macro]
pub fn xmacro(input: TokenStream) -> TokenStream {
    xmacro_expand(input.into()).unwrap().into()
}

/// Does per item expansion of xmacro definitions.
///
/// Unlike [`xmacro!`] which processes everything in one scope, `xmacro_items!` treats each
/// item independently, expanding them as if each were in its own separate scope. This is
/// particularly useful when generating multiple independent items at module level.
///
/// # Example
///
/// ```rust
/// use xmacro::xmacro_items;
///
/// trait IsInteger {}
/// trait IsSigned {}
/// trait IsUnsigned {}
/// trait IsFloat {}
///
/// xmacro_items! {
///     // Each item expands independently in its own scope
///
///     // Generates specific trait implementations
///     impl IsInteger for $(i8  u64) {}
///     impl IsFloat for $(f32 f64) {}
///     impl IsSigned for $(i8 i16 i32 i64 f32 f64) {}
///     impl IsUnsigned for $(u8 u16 u32 u64) {}
/// }
///
/// // Expands to:
/// // impl IsInteger for i8 {}
/// //   same for i16 i32 i64 u8 u16 u32 u64
/// // impl IsFloat for f32 {}
/// // impl IsFloat for f64 {}
/// //impl IsSigned for i8 {}
/// // ... and so on
/// ```
#[allow(clippy::missing_panics_doc)]
#[proc_macro]
pub fn xmacro_items(input: TokenStream) -> TokenStream {
    xmacro_expand_items(input.into()).unwrap().into()
}