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