konst::slice

Function windows

Source
pub const fn windows<T>(slice: &[T], size: usize) -> Windows<'_, T>
Expand description

Const equivalent of <[T]>::windows

§Panics

Panics if size == 0.

§Example

use konst::{iter, slice};

const fn is_sorted(slice: &[u8]) -> bool {
    iter::eval!(slice::windows(slice, 2),all(|w| w[1] > w[0]))
}

assert!(is_sorted(&[3, 5, 8]));
assert!(!is_sorted(&[8, 13, 0]));