Function array_init::from_iter_copy[][src]

pub fn from_iter_copy<Array, I>(iter: I) -> Option<Array> where
    I: IntoIterator<Item = Array::Item>,
    Array: IsArray,
    Array::Item: Copy

Initialize an array 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.

This is preferred over from_iter_copy if you have a Copy type

Examples


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

let four = [1u32,2,3,4];
let mut iter = four.iter().cloned().cycle();
let arr: [u32; 50] = array_init::from_iter_copy(iter).unwrap();