This proc macro crate adds the for_each_int_type macro, which invokes the input macro for each integer type. This is useful when you want to implement some trait for each integer type.
the syntax is as follows (not real code):
for_each_int_type!((mode:)? macro_path (; flags*)?);
for_each_int_type!;
The syntax for the input of for_each_int_type has up to three parts.
The default way to pass input is to just pass the path to a macro. This will invoke that macro for each integer type, including isize and usize.
Optionally, you can include an invocation mode before the macro path. The invocation mode controls how the given macro is invoked. The two modes are each, and args. These two modes come before the input macro path. The default mode when the mode is not included is each. The mode must be followed by a colon :.
// with `each` mode, the target macro is invoked once for each type.
for_each_int_type!;
// with `args` mode, the target macro is invoked once with each int type as input. No separators.
for_each_int_type!;
Additionally, you can also add optional flags after ; after the macro path to control which integer types are passed to the input macro.
// These flags means:
// include signed types
// exclude sized types (isize and usize) as well as 128-bit types (u128, i128)
// include u128
// exclude i8
for_each_int_type!;
The flags are evaluated in the order they are written. You can remove a flag at the begging, then add it back at the end. Or add it at the beginning, and remove it at the end.
You can add flags to a group enclosed with () to add or negate all of them at once.
You can also negate flags to exclude them from the input.
!i8 !
When you are using flags, by default none of the flags are active. You need to add them.
flags
none(no flags. Not very useful, but included for completeness)all(all flags)deterministic(all types besidesisizeandusize)sized(isizeandusize)signedunsigned8(u8andi8)16(u16andi16)32(u32andi32)64(u64andi64)128(u128andi128)u8u16u32u64u128usizei8i16i32i64i128isize