Module std::iterStable
[-] [+]
[src]
Composable external iterators
The Iterator
trait
This module defines Rust's core iteration trait. The Iterator
trait has one
unimplemented method, next
. All other methods are derived through default
methods to perform operations such as zip
, chain
, enumerate
, and fold
.
The goal of this module is to unify iteration across all containers in Rust. An iterator can be considered as a state machine which is used to track which element will be yielded next.
There are various extensions also defined in this module to assist with various
types of iteration, such as the DoubleEndedIterator
for iterating in reverse,
the FromIterator
trait for creating a container from an iterator, and much
more.
Rust's for
loop
The special syntax used by rust's for
loop is based around the Iterator
trait defined in this module. For loops can be viewed as a syntactical expansion
into a loop
, for example, the for
loop in this example is essentially
translated to the loop
below.
let values = vec![1, 2, 3]; // "Syntactical sugar" taking advantage of an iterator for &x in values.iter() { println!("{}", x); } // Rough translation of the iteration without a `for` iterator. let mut it = values.iter(); loop { match it.next() { Some(&x) => { println!("{}", x); } None => { break } } }
This for
loop syntax can be applied to any iterator over any type.
Modules
order | Functions for lexicographical ordering of sequences. |
Structs
Chain | An iterator that strings two iterators together |
Cloned | An iterator that clones the elements of an underlying iterator |
Counter | An infinite iterator starting at |
Cycle | An iterator that repeats endlessly |
Enumerate | An iterator that yields the current count and the element during iteration |
Filter | An iterator that filters the elements of |
FilterMap | An iterator that uses |
FlatMap | An iterator that maps each element to an iterator, and yields the elements of the produced iterators |
Fuse | An iterator that yields |
Inspect | An iterator that calls a function with a reference to each element before yielding it. |
Map | An iterator that maps the values of |
Peekable | An iterator with a |
Range | An iterator over the range [start, stop) |
RangeInclusive | An iterator over the range [start, stop] |
RangeStep | An iterator over the range [start, stop) by |
RangeStepInclusive | An iterator over the range [start, stop] by |
Repeat | An iterator that repeats an element endlessly |
Rev | An double-ended iterator with the direction inverted |
Scan | An iterator to maintain state while iterating another iterator |
Skip | An iterator that skips over |
SkipWhile | An iterator that rejects elements while |
Take | An iterator that only iterates over the first |
TakeWhile | An iterator that only accepts elements while |
Unfold | An iterator that passes mutable state to a closure and yields the result. |
Zip | An iterator that iterates two other iterators simultaneously |
Enums
MinMaxResult |
|
Traits
AdditiveIterator | A trait for iterators over elements which can be added together |
DoubleEndedIterator | A range iterator able to yield elements from both ends |
ExactSizeIterator | An iterator that knows its exact length |
Extend | A type growable from an |
FromIterator | Conversion from an |
IntoIterator | Conversion into an |
Iterator | An interface for dealing with "external iterators". These types of iterators can be resumed at any time as all state is stored internally as opposed to being located on the call stack. |
IteratorExt | An extension trait providing numerous methods applicable to all iterators. |
MultiplicativeIterator | A trait for iterators over elements which can be multiplied together. |
RandomAccessIterator | An object implementing random access indexing by |
Functions
count | Creates a new counter with the specified start/step |
iterate | Create a new iterator that produces an infinite sequence of
repeated applications of the given function |
range | Returns an iterator over the given range [start, stop) (that is, starting at start (inclusive), and ending at stop (exclusive)). |
range_inclusive | Return an iterator over the range [start, stop] |
range_step | Return an iterator over the range [start, stop) by |
range_step_inclusive | Return an iterator over the range [start, stop] by |
repeat | Create a new iterator that endlessly repeats the element |
Type Definitions
Iterate |