It should be easy/trivial to build arrays from iterators, and panic if the iterator is too long or too short.
A pseudocode from_iterator would just look like:
fn from_iterator(foo) -> [T; N] {
let a = foo.next().unwrap();
let b = foo.next().unwrap();
let c = foo.next().unwrap();
let d = foo.next().unwrap();
assert_eq!(foo.next(), None);
[a, b, c, d]
}
It seems to me like with const generics, fixed-sized arrays should be able to impl FromIterator ala the method you have above.
That said, it’d be nice if there was a solution to avoid panicking too, e.g. doing collect() on Option<[T; N]> which returned None if there is a length mismatch.
I think that the recently stabilized TryFrom trait will be a better fit.
BTW I am still not quite sure why we have FromIterator trait. Why collect can’t use B: From<Self> bound instead of B: FromIterator<Self::Item>? Is there some complexity issues due to the coherency rules? Or was it done only for symmetry with IntoIterator (which also may be considered redundant, but makes for loop integration much nicier)?