Repetitive
Rust macro for writing repetitive code in a simpler, more readable, and more powerful way than declarative macros.
Features:
- Repetition with
@for - String/Identifier Concatenation with
@["string" "string"] - Meta Variables with
@let - Conditions with
@ifand@match
Repetition
Repetition is done with the @for keyword.
The body is repeated for each value in the given list.
repetitive!
Expands to:
;
;
;
String/Identifier Concatenation
Concatenation is done using @["a" "b"] syntax.
repetitive!
Expands to:
/// Letter A!
;
/// Letter B!
;
/// Letter C!
;
Meta Variables
Use @let to define variables in the macro context to improve readability.
repetitive!
}
Expands to:
Conditions
Conditions are done using @if.
repetitive!
Generates:
;
;
;
;
Operators And Methods
Macro context expressions support operators and methods.
repetitive!
Expands to:
const _: u32 = 2;
const _: u32 = 4;
const _: u32 = 5;