itertools
Extra iterator adaptors, methods, and macros extending Rust's standard Iterator trait
Repository Health
Technical Analysis
itertools extends Rust’s standard Iterator trait with dozens of additional adaptors, free functions, and macros that the standard library deliberately leaves out — grouping, chunking, Cartesian products, deduplication, multi-way merging, permutations, and more. It’s implemented almost entirely as an extension trait (Itertools) that’s automatically available on any existing iterator once imported, so it composes with std’s own adaptors rather than replacing them.
As one of the most-downloaded crates in the Rust ecosystem (over a billion downloads), it functions as an unofficial-but-standard extension to std::iter, filling gaps that show up constantly in real code — the kind of iterator operations found in Python’s itertools module or functional-language standard libraries but historically absent from Rust’s core.
What You Get
- The
Itertoolsextension trait adding 100+ methods to any existingIteratorimplementation - Grouping and chunking adaptors (
.group_by(),.chunks(),.tuples()) for structuring sequential data - Combinatorial adaptors (
.permutations(),.combinations(),.cartesian_product(),.powerset()) - Deduplication and set-like operations (
.unique(),.unique_by(),.duplicates()) - Macros like
izip!andchain!for ergonomic multi-iterator zipping and chaining
Common Use Cases
- Deduplicating or sorting a stream of values inline within an iterator chain instead of collecting into an intermediate
Vecfirst - Generating combinations, permutations, or Cartesian products for combinatorial or test-data-generation code
- Grouping consecutive elements by a key (
.group_by()) when processing sorted or structured sequential data - Zipping more than two iterators together ergonomically via the
izip!macro instead of nested.zip()calls
Under The Hood
Architecture Roughly 15,600 lines are organized as one implementation file per adaptor or family of related methods (combinations.rs, groupbylazy.rs, intersperse.rs, duplicates_impl.rs, etc.) under src/, with src/adaptors/ holding the lower-level lazy-iterator plumbing each adaptor is built from, and lib.rs assembling everything into the single public Itertools trait — a structure that mirrors the standard library’s own core::iter module organization for familiarity. Tech Stack The crate has effectively zero required dependencies beyond std (with either as an optional lightweight dependency for a couple of adaptors), which matters given how deep in the dependency graph it sits — over a billion downloads means minimizing its own footprint has outsized ecosystem impact. Code Quality tests/ includes a dedicated laziness.rs suite verifying that adaptors don’t eagerly evaluate more of the underlying iterator than necessary (a correctness property specific to iterator libraries), plus specializations.rs testing that performance-optimization overrides (like size_hint) stay behaviorally consistent with the default implementations. API Design Nearly every addition is a method on the Itertools trait rather than a free function, so it chains directly into existing .iter().map().filter() pipelines with one import — deliberately matching std::iter’s own method-chaining idiom rather than introducing a different mental model for the 100+ additional operations it provides.
Used by 18 apps in this directory
PostgresML
AI Development · Databases
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
QuestDB
Analytics · Databases
A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.
Quickwit
Monitoring · Search
Cloud-native search engine for logs and traces, delivering sub-second search directly on S3, GCS, or Azure Blob storage at a fraction of Elasticsearch's cost.
Svix
Automation · Developer Tools
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.
TDengine
Databases
A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.
TensorZero
Ab Testing Experimentation · AI Development · Monitoring
TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.
WrenAI
AI Agents · Analytics · Data Engineering
Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.