iter_chunks_ext
Iterator extension for grouping items.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
What is this?
This crate provides an iterator extension that supports items grouping.
Note that “Grouping” here is dependent on orders, so it is slightly
different from SQL's GROUP BY effect.
Examples
use *;
let items = vec!;
let chunks = &mut items.iter.chunks;
let chunk = &mut chunks.next.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
let chunk = &mut chunks.next.unwrap;
assert_eq!;
assert_eq!;
let chunk = &mut chunks.next.unwrap;
assert_eq!;
assert_eq!;
let chunk = &mut chunks.next;
assert!;
Other options
There are many crates that can group items from iterators.
Followings are some of them.
📦 itertools (Extra iterator tools)
chunk_by- Creates an iterator for grouping.
(To access groups in any order requires heap memory allocation.)
📦 grouping_by (Grouping hash map creator)
grouping_by- Creates hash map grouped by key.
(Heap Memory allocation is required for use of hash maps.)
Highlights
This crate is characterized by following Pros/Cons.
These Pros/Cons are two sides of the same coin.
😊 Pros
Low memory consumption. No heap memory required.
So this crate can work in core environment.
🤔 Cons
Unlike popular iterator methods, iterators and closures are required additional trait bounds.
Clonetrait is required for iterators.Copytrait is required for closures.
Note
I feel my approach is natural. But as of 2025, I cannot find same approach.
This makes me little uneasy. So, please check carefully before using.
Versions
See CHANGELOG.