Crates.io | code-product |
lib.rs | code-product |
version | 0.4.1 |
source | src |
created_at | 2023-12-26 02:32:17.356372 |
updated_at | 2024-01-26 23:09:38.795782 |
description | macro producing multiple expansions |
homepage | |
repository | https://git.pipapo.org/cehteh/code-product.git |
max_upload_size | |
id | 1080579 |
size | 15,903 |
This crate provides two things:
product!{}
and product_items!{}
macros to
generate code using the library as it is useful on its own.The name product
is because it expands to the product 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 code_product::product;
# trait Trait<T>{}
# struct This<T>(T); struct That<T>(T);
# struct Foo; struct Bar;
product!{
// Rather elaborate form with named definitions:
// define `Type` to expand to `This` and `That`
$(Type: (This) (That))
// and inline define `T` to expand to `Foo` and `Bar`
impl Trait<$($T: (Foo)(Bar))> for $Type<$T> {}
}
or
# use code_product::product;
# trait Trait<T>{}
# struct This<T>(T); struct That<T>(T);
# struct Foo; struct Bar;
product!{
// Alternative form inlining definition and reference by index:
impl Trait<$((Foo)(Bar))> for $((This)(That))<$0> {}
}
either of the above will expand four times to:
# trait Trait<T>{}
# struct This<T>(T); struct That<T>(T);
# struct Foo; struct Bar;
impl Trait<Foo> for This<Foo> {}
impl Trait<Foo> for That<Foo> {}
impl Trait<Bar> for This<Bar> {}
impl Trait<Bar> for That<Bar> {}
The detailed syntax for product definitions is described at: The product syntax.