Crate itertools
Extra iterator adaptors, functions and macros.
To extend Iterator with methods in this crate, import
the Itertools trait:
#
use Itertools;
Now, new methods like interleave
are available on all iterators:
use Itertools;
let it = .interleave;
assert_equal;
Most iterator methods are also provided as functions (with the benefit
that they convert parameters using IntoIterator):
use interleave;
for elt in interleave
Crate Features
use_std- Enabled by default.
- Disable to compile itertools using
#![no_std]. This disables any item that depend on allocations (see theuse_allocfeature) and hash maps (likeunique,counts,into_grouping_mapand more).
use_alloc- Enabled by default.
- Enables any item that depend on allocations (like
chunk_by,kmerge,joinand many more).
Rust Version
This version of itertools requires Rust 1.63.0 or later.
Modules
Enums
-
Diff
A type returned by the
diff_withfunction. - Either
- EitherOrBoth Value that either holds a single A or B, or both.
-
FoldWhile
An enum used for controlling the execution of
fold_while. -
MinMaxResult
MinMaxResultis an enum returned byminmax. -
Position
The first component of the value yielded by
WithPosition. Indicates the position of this element in the iterator results.
Traits
-
Itertools
An
Iteratorblanket implementation that provides extra adaptors and methods. - MultiUnzip An iterator that can be unzipped into multiple collections.
- PeekingNext An iterator that allows peeking at an element before deciding to accept it.
Functions
-
assert_equal
Assert that two iterables produce equal sequences, with the same
semantics as
equal(a, b). -
concat
Combine all an iterator's elements into one element by using
Extend. -
cons_tuples
Create an iterator that maps for example iterators of
((A, B), C)to(A, B, C). -
diff_with
Compares every element yielded by both
iandjwith the given function in lock-step and returns aDiffwhich describes howjdiffers fromi. -
equal
Return
trueif both iterables produce equal sequences (elements pairwise equal and sequences of the same length),falseotherwise. - iterate Creates a new iterator that infinitely applies function to value and yields results.
- kmerge_by Create an iterator that merges elements of the contained iterators.
- multiunzip Converts an iterator of tuples into a tuple of containers.
-
multizip
An iterator that generalizes
.zip()and allows running multiple iterators in lockstep. -
partition
Partition a sequence using predicate
predso that elements that map totrueare placed before elements which map tofalse. -
process_results
“Lift” a function of the values of an iterator so that it can process
an iterator of
Resultvalues instead. -
repeat_n
Create an iterator that produces
nrepetitions ofelement. - unfold Creates a new unfold source with the specified closure as the "iterator function" and an initial state to eventually pass to the closure