macro_rules! plus_1 {
($t:tt) => { ... };
($a:tt $($bs:tt)+) => { ... };
}
Expand description
! This library holds macros which can be used to generate enums as labels ! for fixed instances of lazily allocated literal data. ! Macro to generate numbers in constant contexts, e.g., the constant usize bound in the type signature of a fixed size array.
Example
The following illustrates this macro being used to generate a usize
constant N
equal to the number of token tree
s provided.
In this case, we know we want it to be three – however, within the context of another macro, we would be able to use this to find a statically known bound for a certain syntactic repetition.
let three_bytes: [u8; plus_1!(a b c)] = [0, 1, 2];
Note that the actual tokens provided are discarded, as each invocation of
this macro is syntactically equivalent to a repeated addition of 1
.