itertools
Extra iterator adaptors for Rust such as chunks, tuples, sorted, group_by and dedup.
Official Documentation ↗itertools 0.13 / Rust 1.63+. Check the official docs for the latest API surface.Installation
cargo add itertoolsMethods
No methods match this filter.
Overview
itertools extends Rust iterators with adaptors that are common in other languages but missing from std, such as chunking, sorting, deduplication and grouping.
Core Methods
Chains like chunks, tuples, sorted, dedup, unique and group_by operate on any iterator. Some are lazy, while sorting and dedup require buffering or ordered input.
Usage Notes
Sort before group_by, prefer lazy adaptors in pipelines, and collect only when needed. itertools composes with std iterator methods without extra allocation where lazy.
Common Pitfalls
group_by without sorting silently splits groups. sorted buffers everything, which is wrong for streams. duplicate iterators from tuples keep the source alive, so drop them when done.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/itertools/latest/itertools/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:27.726Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Strip Prefix Error The error returned by Itertools::strip_prefix and Itertools::strip_prefix_by when the iterator does not start with the requested prefix. (https://docs.rs/itertools/latest/itertools/)
FAQ
- How does group_by differ from a map-based group?
- group_by only groups consecutive equal keys, so sort first for full grouping. A HashMap group keyed by a value works without ordering but loses order.
- Are the adaptors lazy?
- Most are lazy, but sorted must consume and buffer the whole iterator before yielding, so it cannot be used on infinite iterators.
- How do I use tuples?
- The tuples adaptor splits an iterator of tuples into separate iterators, which is convenient when constructing multiple collections in one pass.
Report a problem with this API docOpens a pre-filled issue on GitHub.