forint/lib.rs
1mod foreach;
2use foreach::ForEachIntTypeInput;
3
4use proc_macro::TokenStream;
5use quote::quote;
6
7/// Takes as input a path to a macro and optional flags. Additionally, you can also add the `args:` or `each:`
8/// modifiers to the beginning of the input in order to control how the macro is invoked. With `each:`, the macro
9/// is invoked for each type. With `args:`, the macro is invoked with each type as input (without separators).
10/// The default mode is `each:`.
11/// # Example
12/// ```rust,no_run
13/// for_each_int_type!(each: path_to_macro);
14/// // or
15/// for_each_int_type!(args: path_to_macro);
16/// // or
17/// for_each_int_type!(path_to_macro; signed);
18/// // or
19/// for_each_int_type!(path_to_macro; signed !sized !(64, 128));
20/// ```
21/// # Flags
22/// - `none`
23/// - `all`
24/// - `deterministic` (all types besides `isize` and `usize`)
25/// - `sized` (`isize` and `usize`)
26/// - `signed` (`i8`, `i16`, `i32`, `i64`, `i128`, and `isize`)
27/// - `unsigned` (`u8`, `u16`, `u32`, `u64`, `u128`, and `usize`)
28/// - `8` (`u8` and `i8`)
29/// - `16` (`u16` and `i16`)
30/// - `32` (`u32` and `i32`)
31/// - `64` (`u64` and `i64`)
32/// - `128` (`u128` and `i128`)
33/// - `u8`
34/// - `u16`
35/// - `u32`
36/// - `u64`
37/// - `u128`
38/// - `usize`
39/// - `i8`
40/// - `i16`
41/// - `i32`
42/// - `i64`
43/// - `i128`
44/// - `isize`
45///
46/// Each flag can be negated using `!`.
47/// ```rust, no_run
48/// for_each_int_type!(no_sized; all !sized);
49/// ```
50///
51/// Flags can also be placed in groups, that can also be negated:
52/// ```rust, no_run
53/// for_each_int_type!(groups; signed !(isize i128) (u8 u16))
54/// ```
55/// When adding flags, you must add flags first for them to be active.
56/// All flags start off inactive. A good initial flag is the `all` flag
57/// so that you can negate the flags you don't want.
58#[proc_macro]
59pub fn for_each_int_type(input: TokenStream) -> TokenStream {
60 let parsed = syn::parse_macro_input!(input as ForEachIntTypeInput);
61 quote!( #parsed ).into()
62}