ary - The array literal of the gods.
Rust provides two syntaxes for array literals: [a, b, c], and [x; count].
When building complex const arrays, having only these two forms can be
quite limiting.
This library provides the ary![] macro to improve this situation.
Array Splatting
First, we allow an element expression to begin with in, which indicates
it should be flattened into the overall array. The expression must be a
const array or slice. For example:
const MACRO: & = b"ary![]";
assert_eq!;
assert_eq!;
Note that because this may be any const expression, we can easily build
varying-size arrays.
const
const WORDS: & = &ary!;
assert_eq!;
Range Modifiers
After all of the elements, modifiers for ranges of the constructed array
can be specified by placing range-value pairs after a => token.
const ARRAY: & = &ary!;
assert_eq!;
// You can use .. to replace the contents of the whole array.
const RANGE: & = &ary!;
assert_eq!;
Inferring Array Length from Ranges
It is possible to skip the element expressions and proceed to using range modifiers; in this case, the size of the array will be inferred from the upper bounds of the given modifiers.
const EVENS: = ary!;
assert_eq!;
// Unbounded ranges do not contribute to the inferred size.
const EMPTY: = ary!;
// Lower bounds of unbounded-above ranges *do* contribute, though.
const NONEMPTY: = ary!;