macro_rules! axr {
( $a:ident..$b:ident ) => { ... };
( $a:ident..=$b:ident ) => { ... };
( $a:ident..$b:expr ) => { ... };
( $a:ident..=$b:expr ) => { ... };
( ..$a:ident ) => { ... };
( ..=$a:ident ) => { ... };
( $a:ident.. ) => { ... };
( ($a:expr)..$b:ident ) => { ... };
( ($a:expr)..=$b:ident ) => { ... };
}
Expand description
Converts a range of identifiers and/or usize
expressions to a range of usize
values
Using any identifiers apart from x, y, z or w will result in a compile time error
It is recommended to use parentheses when calling this macro for clarity
Possible Variations
// PLEASE NOTE!
// x => 0usize
// y => 1
// z => 2
// w => 3
// Range with identifiers
assert_eq!(axr!(x..z), 0..2);
// RangeInclusive with identifiers
assert_eq!(axr!(y..=w), 1..=3);
// RangeTo with identifiers
assert_eq!(axr!(..z), ..2);
// RangeToInclusive with identifiers
assert_eq!(axr!(..=w), ..=3);
// RangeFrom with identifier
assert_eq!(axr!(y..), 1..);
// Range with identifier and expression
assert_eq!(axr!(x..10), 0..10);
// RangeInclusive with identifier and expression
assert_eq!(axr!(x..=7), 0..=7);
// Range with expression and identifier
// The parentheses around the expression are compulsory
assert_eq!(axr!((0)..z), 0..2);
// RangeInclusive with expression and identifier
// The parentheses around the expression are compulsory
assert_eq!(axr!((1)..=w), 1..=3);