Function konst::slice::iter_copied

source ·
pub const fn iter_copied<T>(slice: &[T]) -> IterCopied<'_, T>
where T: Copy,
Expand description

A const equivalent of slice.iter().copied()

§Example

use konst::{iter, slice};

const fn find_even(slice: &[u32]) -> Option<u32> {
    iter::eval!(slice::iter_copied(slice),find(|elem| *elem % 2 == 0))
}

assert_eq!(find_even(&[]), None);
assert_eq!(find_even(&[1]), None);
assert_eq!(find_even(&[1, 2]), Some(2));
assert_eq!(find_even(&[5, 4, 3, 2, 1]), Some(4));