Range expressions allows to define integer ranges that can used:
To loop on integers in a
forstatement.To take a slice of an object (array, string, ...).
To match a value inside a
matchstatement.
See Match, Slices and for
for practical usages of ranges.
For the moment, we just present in Table 1 the syntax to
use when defining a range.
A Range being
also an Iterator,
we may use Iterator
methods on it like rev(). See Table 2 for some
interesting iterator methods.
Table 1:Range syntax
Table 2:Some methods of the Iterator trait
Method | Description |
|---|---|
| Test if all elements satisfy the predicate |
| Test if any element satisfies the predicate |
| Construct a new |
| Transform the iterator into a collection. |
| Consume the iterator and return the number of iterations. |
| Repeat endlessly. |
| Create a new |
| Create a new |
| Call the closure |
| Create a new |
| Return the max element. |
| Return the min element. |
| Multiply all elements. |
| Reduce the elements using the reducing operator |
| Reverse the iterator. |
| Skip the |
| Step by the given amount. |
| Sum the elements. |
| Yield only the |
| Convert an iterator of pairs into a pair of containers. |
| Zip two iterators into an iterator of pairs. |