XMacro
A powerful macro system for generating repetitive code using a simple and expressive syntax.
This crate provides two main components:
- A procedural macro library that enables code generation through template expansion
- Two public macros: [
xmacro!
] and [xmacro_items!
] for direct use in your code
This crate supersedes the code_product
crate.
Key Features
- Define reusable code templates with substitution points
- Generate multiple variations of code using sets of values
- Support for nested scopes and named definitions
- Table-based code generation for row-wise expansion
- Clear and maintainable syntax for complex code generation
Usage
For example given are the two sets of defintions 'Foo and Bar' and 'This and That', showing different syntactic variants:
Normal definitions expans each-by-each:
# use xmacro;
; ;
; ;
xmacro!
or
# use xmacro;
#
# ; ;
# ; ;
xmacro!
or use the table syntax expands per table row and gives more control what gets expansed:
# use xmacro;
#
# ; ;
# ; ;
xmacro!
either of the above will expand four times to:
# doctest_ignore!
Please refer to the [xmacro_lib
] crate for a elaborate
description of the macro syntax and semantic.