Sometimes, to simplify repetitive code without introducing a function (which is kinda verbose), I’d like to do something like:
for (a, b) in vec![
(foo, 4),
(bar, 0),
(baz, 7),
] {
// ...
}
… where the loop takes ownership of the values. However, the heap allocation in vec! here seems wasteful: the number of items is known at compile time, so it should be possible to allocate them on the stack.
The IntoIterator trait is already implemented for &'a [T, $N] for $N up to 32, yielding &'a T. Could it also be possible to implement it for [T, $N], taking ownership and yielding T? Getting the destructor right (in case the iterator was not consumed to its end) seems tricky, but I don’t see a reason it would be impossible.