pub fn from_iter_reversed<Iterable, T, const N: usize>(
    iterable: Iterable
) -> Option<[T; N]>where
    Iterable: IntoIterator<Item = T>,
Expand description

Initialize an array in reverse given an iterator

We will iterate until the array is full or the iterator is exhausted. Returns None if the iterator is exhausted before we can fill the array.

  • Once the array is full, extra elements from the iterator (if any) won’t be consumed.

Examples

// Initialize an array from an iterator
// producing an array of [4,3,2,1] repeated, finishing with 1.

let four = [1,2,3,4];
let mut iter = four.iter().copied().cycle();
let arr: [u32; 10] = array_init::from_iter_reversed(iter).unwrap();
assert_eq!(arr, [2, 1, 4, 3, 2, 1, 4, 3, 2, 1]);