3 #![feature(generic_associated_types)]
6 type Item<'a> where Self: 'a;
8 fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
10 fn for_each<F>(mut self, mut f: F)
11 where Self: Sized, F: for<'a> FnMut(Self::Item<'a>)
13 while let Some(item) = self.next() {
19 pub struct Windows<T> {
26 pub fn new(items: Vec<T>, len: usize) -> Self {
27 Self { items, start: 0, len }
31 impl<T> Iter for Windows<T> {
32 type Item<'a> = &'a mut [T] where T: 'a;
34 fn next<'a>(&'a mut self) -> Option<Self::Item<'a>> {
35 let slice = self.items.get_mut(self.start..self.start + self.len)?;
42 Windows::new(vec![1, 2, 3, 4, 5], 3)
43 .for_each(|slice| println!("{:?}", slice));