iter_chunks_ext 0.1.0

Iterator extension for grouping items.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 1 items with examples
  • Size
  • Source code size: 21.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 583.99 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nossie531/iter_chunks_ext
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nossie531

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 iter_chunks_ext::prelude::*;

let items = vec![("a", 0), ("a", 1), ("b", 0), ("a", 2)];
let chunks = &mut items.iter().chunks(|x| x.0);

let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("a", 0)));
assert_eq!(chunk.next(), Some(&("a", 1)));
assert_eq!(chunk.next(), None);

let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("b", 0)));
assert_eq!(chunk.next(), None);

let chunk = &mut chunks.next().unwrap();
assert_eq!(chunk.next(), Some(&("a", 2)));
assert_eq!(chunk.next(), None);

let chunk = &mut chunks.next();
assert!(chunk.is_none());

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.

  • Clone trait is required for iterators.
  • Copy trait 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.