#iterator #chunks #const-generics #iterable #chunked

chunk_iter

Chunked iterator generic over any iterator

5 releases

0.1.5 Jul 25, 2022
0.1.4 Jul 23, 2022
0.1.3 Jul 29, 2021
0.1.1 May 18, 2021

#1781 in Rust patterns

MIT OR Unlicense

8KB
112 lines

chunk_iter

It makes any iterable into chunks, using const generics.

#![no_std]

This crate is no_std.

Usage

use chunk_iter::ChunkIter;

for x in iter.chunks::<3>() {
    println!("{:?}", x); // x is a size 3 array of what iter contains
}

lib.rs:

Import the trait and use it:

use chunk_iter::ChunkIter;

let iter = vec![0, 1, 2, 3, 4, 5, 6].into_iter();
let mut chunks = iter.chunks::<3>();
assert_eq!(chunks.next(), Some([0, 1, 2]));
assert_eq!(chunks.next(), Some([3, 4, 5]));
assert_eq!(chunks.next(), None);

No runtime deps