1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use code_product_lib::*;
/// Macro doing product expansions.
///
/// Productions are defined using the
/// [syntax](../code_product_lib/index.html#the-product-syntax).
///
/// # Example
///
/// Define 3 tuple structures each with a single i32 field and use them:
///
/// ```
/// # use code_product_macro::*;
/// product! {
/// struct @((Foo)(Bar)(Baz)) (i32);
/// }
///
/// let _a = Foo(1);
/// let _b = Bar(2);
/// let _c = Baz(3);
/// ```
#[proc_macro]
pub fn product(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand_products(input.into(), ScopeMode::Expand).into()
}
/// Macro doing product expansions per item. This means that (on toplevel) automatic
/// scopes are generated up and including to the first braced block or semicolon. Then these
/// scopes become independently expanded.
///
/// # Example
///
/// Define structures, the first two with `&str` members and remaining two a single i32
/// field and use them:
/// ```
/// # use code_product_macro::*;
/// product_items! {
/// struct @((Foo)(Bar)) {
/// s: &'static str
/// }
/// struct @((Baz)(Barf)) (i32);
/// }
///
/// let _a = Foo { s: "one" };
/// let _b = Bar { s: "two" };
/// let _c = Baz(3);
/// let _c = Barf(4);
/// ```
#[proc_macro]
pub fn product_items(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand_products(input.into(), ScopeMode::AutoBraceSemi).into()
}