Obsoletion Notice
*** This crate is superseded by the xmacro/xmacro_lib crate ***
- Migrate your projects to xmacros.
- Don't use it for new Code.
Code Product
This crate provides two things:
- A library to generate code by repetively expanding macros. This is the primary objective of this crate as it enables code generation in a convenient way from other proc macros. The Syntax is there as well.
- The standalone
product!{}andproduct_items!{}macros to generate code using the library as it is useful on its own.
Use-Cases
This macro system is useful to generate boilerplate code that repeats in similar ways.
Product expansion example
The name product is because it expands to the product (each by each) of all defined
sets. For example given are the two sets of defintions 'Foo and Bar' and 'This and That',
showing different syntactic variants:
# use product;
#
# ; ;
# ; ;
product!
or
# use product;
#
# ; ;
# ; ;
product!
either of the above will expand four times to:
#
# ; ;
# ; ;
Linear expansion example
In linear expansion scopes in square brackets each definition has to define the same number
of itens. These are then iterated together. This gives more control over the expansions as
each possible combination has to be defined manually.
Exmaple: Pair Substr with &str and with CowStr and its reversed forms.
product! {
$[
$(Lhs: (SubStr)(&str)(SubStr)(CowStr))
$(Rhs: (&str)(SubStr)(CowStr)(SubStr))
impl PartialOrd<$Rhs> for $Lhs {
fn partial_cmp(&self, other: &$Rhs) -> Option<std::cmp::Ordering> {
(**self).partial_cmp(other)
}
}
]
}