iter
import std::core::iter; — in the prelude · source
Types
Iterator
type trait Iterator {
type Item;
next(mut &this) -> Option<This::Item>;
count(mut &this) -> u64;
fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> Acc;
for_each(mut &this, f: (This::Item) -> void) -> void;
take(this, n: u64) -> TakeIter<This>;
skip(this, n: u64) -> SkipIter<This>;
map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>;
filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>;
chain<J>(this, other: J) -> ChainIter<This, J>;
enumerate(this) -> EnumerateIter<This>;
zip<J>(this, other: J) -> ZipIter<This, J>;
any(mut &this, pred: (This::Item) -> boolean) -> boolean;
all(mut &this, pred: (This::Item) -> boolean) -> boolean;
find(mut &this, pred: (&This::Item) -> boolean) -> Option<This::Item>;
min(mut &this) -> Option<This::Item>
where This::Item: Ord;
max(mut &this) -> Option<This::Item>
where This::Item: Ord;
}
Iterator has exactly one required method — next — and everything else is derived from it. for (x in seq) drives the scrutinee through this trait, so anything that implements it works in a for loop. Item is an associated type; implement Iterator<T> for X is positional sugar for binding it.
type struct Counter { n: i32; }
implement trait Iterator<i32> for struct Counter {
next(mut &this) -> Option<i32> {
if (this.n >= 5) { return Option::<i32>::None; }
this.n = this.n + 1;
return Option::<i32>::Some(this.n);
}
}
mut c: Counter = Counter { n: 0 };
for (v in c.take(3)) { println(f"{v}"); }
Associated types
| Type | Notes |
|---|---|
Item | The element type this iterator yields. Each implementor binds it once (positional sugar: implement Iterator<T> for X => Item = T); refer to it as This::Item inside the trait and X::Item outside. |
Methods
next(mut &this) -> Option<This::Item>;
next(mut &this) -> Option<This::Item>;Advance the sequence and return the next value, or None when exhausted. Calling next again after None may return None forever or may panic; implementations should document which.
count(mut &this) -> u64;
count(mut &this) -> u64;Number of remaining elements. The default walks the iterator to count, consuming it. Implementations with O(1) knowledge of their length should override.
fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> Acc;
fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> Acc;Reduce the sequence to a single value. initial is the starting accumulator; f folds each element into it.
for_each(mut &this, f: (This::Item) -> void) -> void;
for_each(mut &this, f: (This::Item) -> void) -> void;Call f on each element, discarding the results. The natural way to consume an iterator purely for its side effects.
take(this, n: u64) -> TakeIter<This>;
take(this, n: u64) -> TakeIter<This>;Yield at most the first n elements, then stop.
skip(this, n: u64) -> SkipIter<This>;
skip(this, n: u64) -> SkipIter<This>;Discard the first n elements, then yield the rest. An iterator with fewer than n elements is drained and yields nothing.
map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>;
map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>;Transform each element with f, yielding the results. f must be a non-capturing function (a plain fn or a non-capturing lambda).
filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>;
filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>;Yield only the elements for which pred returns true. pred must be a non-capturing function. It BORROWS each element: the element it keeps is the one yielded, so it cannot also be handed to pred.
chain<J>(this, other: J) -> ChainIter<This, J>;
chain<J>(this, other: J) -> ChainIter<This, J>;Yield every element of this, then every element of other. other must be an Iterator with the same Item type - the shared element type is enforced by ChainIter's impl bounds.
enumerate(this) -> EnumerateIter<This>;
enumerate(this) -> EnumerateIter<This>;Yield (index, value) pairs, the index counting up from 0 as a u64. The pair is Pair<u64, Item>: p.first is the index, p.second the element. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
zip<J>(this, other: J) -> ZipIter<This, J>;
zip<J>(this, other: J) -> ZipIter<This, J>;Yield pairs (a, b) drawing a from this and b from other, stopping as soon as either iterator is exhausted. The pair is Pair<Item, B> where B is other's element type: p.first comes from this, p.second from other. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
any(mut &this, pred: (This::Item) -> boolean) -> boolean;
any(mut &this, pred: (This::Item) -> boolean) -> boolean;True if pred holds for at least one element. Short-circuits on the first match; consumes elements up to it.
all(mut &this, pred: (This::Item) -> boolean) -> boolean;
all(mut &this, pred: (This::Item) -> boolean) -> boolean;True if pred holds for every element. Short-circuits on the first failure; vacuously true for an empty iterator.
find(mut &this, pred: (&This::Item) -> boolean) -> Option<This::Item>;
find(mut &this, pred: (&This::Item) -> boolean) -> Option<This::Item>;The first element for which pred holds, or None. Consumes elements up to and including the match. pred borrows each element, since the one it accepts is returned.
min(mut &this) -> Option<This::Item> where This::Item: Ord;
min(mut &this) -> Option<This::Item> where This::Item: Ord;The smallest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the FIRST minimal element wins (only a strictly smaller element displaces the running best), so min and max of equal elements differ. Available only where the element type is Ord - the where This::Item: Ord associated-type projection bound; adapters whose element is never Ord (e.g. enumerate/zip, which yield Pair) do not carry it.
max(mut &this) -> Option<This::Item> where This::Item: Ord;
max(mut &this) -> Option<This::Item> where This::Item: Ord;The largest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the LAST maximal element wins (an equal-or-greater element displaces the running best), the mirror of min.
Lazy adapters
Each of these returns a wrapper that is itself an Iterator, so they compose. Nothing is computed until something consumes the chain.
take and skip cut the front of the sequence, map and filter transform and select, chain runs a second iterator of the same Item after the first, and enumerate and zip pair each element with its index or with another iterator's element — stopping when either side runs out.
f and pred must be non-capturing — a plain function or a non-capturing lambda.
enumerate and zip yield Pair rather than a tuple because Cryo has no heterogeneous tuple literal.
The adapter types
type struct TakeIter<I> {
inner: I;
remaining: u64;
static new(inner: I, n: u64) -> TakeIter<I>;
}
type struct SkipIter<I> {
inner: I;
remaining: u64;
static new(inner: I, n: u64) -> SkipIter<I>;
}
type struct MapIter<I, O> where I: Iterator {
inner: I;
f: (I::Item) -> O;
static new(inner: I, f: (I::Item) -> O) -> MapIter<I, O>;
}
type struct FilterIter<I> where I: Iterator {
inner: I;
pred: (&I::Item) -> boolean;
static new(inner: I, pred: (&I::Item) -> boolean) -> FilterIter<I>;
}
type struct ChainIter<I, J> {
first: I;
second: J;
first_done: boolean;
static new(first: I, second: J) -> ChainIter<I, J>;
}
type struct EnumerateIter<I> {
inner: I;
index: u64;
static new(inner: I) -> EnumerateIter<I>;
}
type struct ZipIter<I, J> {
first: I;
second: J;
static new(first: I, second: J) -> ZipIter<I, J>;
}
The wrappers the adapters return are public structs, so you can name one in a signature when the opaque implement Iterator<T> is not enough. Each is an Iterator in turn; their impls are listed under Implementors.
Eager consumers
count, fold, and for_each walk the whole iterator; any, all, and find short-circuit; the predicates of filter and find borrow the element ((&Item) -> boolean) rather than consuming it, so the element they keep is still whole; min and max need Item: Ord and return None on an empty sequence.
On ties min keeps the first minimal element and max keeps the last maximal one, matching the conventional behaviour.
The adapters resolve on any concrete Iterator receiver, including your own structs. Re-adapting a local whose type is the opaque implement Iterator<T> works when its initialiser is a concrete constructor (mut it: implement Iterator<i32> = Range::<i32>::new(0, 10); it.take(3)); a local initialised from a producer that itself returns an opaque iterator is still restricted, so chain directly off the source in that case.
Implementors
Every iterator in the library, including the adapters above and the by-reference cursors the containers hand out:
implement<I, A> trait Iterator<A> for struct TakeIter<I> where I: Iterator<A>
implement<I, A> trait Iterator<A> for struct SkipIter<I> where I: Iterator<A>
implement<I, O> trait Iterator<O> for struct MapIter<I, O> where I: Iterator
implement<I> trait Iterator<I::Item> for struct FilterIter<I> where I: Iterator
implement<I, J, A> trait Iterator<A> for struct ChainIter<I, J> where I: Iterator<A>, J: Iterator<A>
implement<I> trait Iterator<Pair<u64, I::Item>> for struct EnumerateIter<I> where I: Iterator
implement<I, J, A, O> trait Iterator<Pair<A, O>> for struct ZipIter<I, J> where I: Iterator<A>, J: Iterator<O>
implement<T> trait Iterator<T*> for struct RefIter<T>
std::collections::array
implement<I, T> trait Iterator<T> for struct CopiedIter<I> where I: Iterator<T*>, T: Copy
std::collections::array
implement<I, T> trait Iterator<T> for struct ClonedIter<I> where I: Iterator<T*>, T: Clone
std::collections::array
implement<K, V> trait Iterator<Pair<K, V>> for struct HashMapIter<K, V> where K: Copy, V: Copy
std::collections::hashmap
implement<K, V> trait Iterator<K> for struct KeysIter<K, V>
std::collections::hashmap
implement<K, V> trait Iterator<V> for struct ValuesIter<K, V>
std::collections::hashmap
implement<K, V> trait Iterator<Pair<K*, V*>> for struct EntriesRefIter<K, V>
std::collections::hashmap
implement<K, V> trait Iterator<K*> for struct KeysRefIter<K, V>
std::collections::hashmap
implement<K, V> trait Iterator<V*> for struct ValuesRefIter<K, V>
std::collections::hashmap
implement<T> trait Iterator<T> for struct HashSetIter<T> where T: Copy
std::collections::hashset
implement<T> trait Iterator<T*> for struct HashSetRefIter<T>
std::collections::hashset
implement trait Iterator<Str> for struct SplitIter
std::collections::str
implement trait Iterator<u32> for struct Chars
std::collections::str
implement trait Iterator<Pair<u64, u32>> for struct CharIndices
std::collections::str
implement<T> trait Iterator<T> for struct Range<T> where T: Step
std::core::ops
implement<T> trait Iterator<T> for struct RangeInclusive<T> where T: Step
std::core::ops
implement<T> trait Iterator<T> for struct SliceIter<T>
std::core::slice
implement trait Iterator<DirEntry> for struct ReadDir
std::fs::dir
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type trait Name : Base {
method(&this, other: &This) -> Ret;
}Names a set of methods a type may implement. Inside the body This is the implementing type; methods may carry default bodies, and a trait may require a base trait (type trait Ord : Eq). Generic code asks for a trait with where T: Name.
type trait Iterator {
type Item;
next(mut &this) -> Option<This::Item>;
count(mut &this) -> u64;
fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> Acc;
for_each(mut &this, f: (This::Item) -> void) -> void;
take(this, n: u64) -> TakeIter<This>;
skip(this, n: u64) -> SkipIter<This>;
map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>;
filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>;
chain<J>(this, other: J) -> ChainIter<This, J>;
// … 7 more
}type Item;
type Output = i64;An associated type on a trait: named in the trait body, filled in by each implementation, and referred to as This::Item or I::Item.
Iterator::type ItemThe element type this iterator yields. Each implementor binds it once (positional sugar: implement Iterator<T> for X => Item = T); refer to it as This::Item inside the trait and X::Item outside.
Iterator::next(mut &this) -> Option<This::Item>Advance the sequence and return the next value, or None when exhausted. Calling next again after None may return None forever or may panic; implementations should document which.
mut &this
mut &TypeAn exclusive, mutating borrow. As a receiver, mut &this lets the method modify the fields - and callers can see that from the signature alone. As a parameter type, mut &T lets the callee mutate through the reference while the caller keeps ownership.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
ThisThe implementing type, inside a trait or implement body. other: &This in a trait method is a reference to whichever type implements it; This::Item names an associated type.
Iterator::type ItemThe element type this iterator yields. Each implementor binds it once (positional sugar: implement Iterator<T> for X => Item = T); refer to it as This::Item inside the trait and X::Item outside.
Iterator::count(mut &this) -> u64Number of remaining elements. The default walks the iterator to count, consuming it. Implementations with O(1) knowledge of their length should override.
Iterator::fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> AccReduce the sequence to a single value. initial is the starting accumulator; f folds each element into it.
type parameter Acc(parameter) initial: Acctype parameter Acc(parameter) f: (Acc, This::Item) -> AccIterator::for_each(mut &this, f: (This::Item) -> void) -> voidCall f on each element, discarding the results. The natural way to consume an iterator purely for its side effects.
(parameter) f: (This::Item) -> voidIterator::take(this, n: u64) -> TakeIter<This>Yield at most the first n elements, then stop.
(parameter) n: u64type struct TakeIter<I> {
inner: I;
remaining: u64;
}Adapter yielding at most remaining elements from inner.
Iterator::skip(this, n: u64) -> SkipIter<This>Discard the first n elements, then yield the rest. An iterator with fewer than n elements is drained and yields nothing.
type struct SkipIter<I> {
inner: I;
remaining: u64;
}Adapter that drops the first remaining elements of inner on the first next, then passes the rest through. remaining counts DOWN as elements are skipped; once it hits 0 the adapter is transparent.
Iterator::map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>Transform each element with f, yielding the results. f must be a non-capturing function (a plain fn or a non-capturing lambda).
type parameter B(parameter) f: (This::Item) -> Btype parameter Btype struct MapIter<I, O> where I: Iterator {
inner: I;
}Adapter applying f to each element of inner. The input element type is the inner iterator's associated item I::Item; O is the mapped result (Output) type, the only element-type struct parameter needed.
Iterator::filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>Yield only the elements for which pred returns true. pred must be a non-capturing function. It BORROWS each element: the element it keeps is the one yielded, so it cannot also be handed to pred.
(parameter) pred: (&This::Item) -> booleantype struct FilterIter<I> where I: Iterator {
inner: I;
}Adapter yielding only the elements of inner for which pred holds.
Iterator::chain<J>(this, other: J) -> ChainIter<This, J>Yield every element of this, then every element of other. other must be an Iterator with the same Item type - the shared element type is enforced by ChainIter's impl bounds.
type parameter J(parameter) other: Jtype parameter Jtype struct ChainIter<I, J> {
first: I;
second: J;
first_done: boolean;
}Adapter concatenating two iterators of the same element type: it drains first, then second. Both inner element types are pinned to the shared A by the where-bounds.
Iterator::enumerate(this) -> EnumerateIter<This>Yield (index, value) pairs, the index counting up from 0 as a u64. The pair is Pair<u64, Item>: p.first is the index, p.second the element. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
type struct EnumerateIter<I> {
inner: I;
index: u64;
}Adapter pairing each element of inner with its 0-based index. The element type is the inner iterator's associated item I::Item; the yielded item is Pair<u64, I::Item>.
Iterator::zip<J>(this, other: J) -> ZipIter<This, J>Yield pairs (a, b) drawing a from this and b from other, stopping as soon as either iterator is exhausted. The pair is Pair<Item, B> where B is other's element type: p.first comes from this, p.second from other. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
type parameter Jtype struct ZipIter<I, J> {
first: I;
second: J;
}Adapter pairing two iterators positionally, yielding Pair<A, O> until either side runs out. Chain-shaped: the element types A (from I) and O (from J) live only in the impl where-bounds, not as struct parameters, so the receiver type only mentions the two inner iterators.
Iterator::any(mut &this, pred: (This::Item) -> boolean) -> booleanTrue if pred holds for at least one element. Short-circuits on the first match; consumes elements up to it.
(parameter) pred: (This::Item) -> booleanIterator::all(mut &this, pred: (This::Item) -> boolean) -> booleanTrue if pred holds for every element. Short-circuits on the first failure; vacuously true for an empty iterator.
Iterator::find(mut &this, pred: (&This::Item) -> boolean) -> Option<This::Item>The first element for which pred holds, or None. Consumes elements up to and including the match. pred borrows each element, since the one it accepts is returned.
Iterator::min(mut &this) -> Option<This::Item>
where This::Item: OrdThe smallest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the FIRST minimal element wins (only a strictly smaller element displaces the running best), so min and max of equal elements differ.
where T: Ord + Clone, U: HashConstrains generic parameters to types that implement the listed traits, which is what makes those traits' methods callable on T. Bounds on one parameter join with +; parameters separate with ,. A where on a single method narrows the type's parameter for that method only.
type trait Ord : Eq {
compare(&this, other: &This) -> Ordering;
}Types that have a total order: every pair is Less, Equal, or Greater. compare must be consistent with equals: if a.equals(b) then a.compare(b) == Equal.
Iterator::max(mut &this) -> Option<This::Item>
where This::Item: OrdThe largest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the LAST maximal element wins (an equal-or-greater element displaces the running best), the mirror of min.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct CounterCounter.n: i32implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait Iterator {
type Item;
next(mut &this) -> Option<This::Item>;
count(mut &this) -> u64;
fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> Acc;
for_each(mut &this, f: (This::Item) -> void) -> void;
take(this, n: u64) -> TakeIter<This>;
skip(this, n: u64) -> SkipIter<This>;
map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>;
filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>;
chain<J>(this, other: J) -> ChainIter<This, J>;
// … 7 more
}implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype struct CounterCounter::next(mut &this) -> Option<i32>if (condition) { ... } else if (condition) { ... } else { ... }Branches on a parenthesised boolean condition. Bodies are always braced; there is no single-statement form. Used as an expression, both arms are required and must produce the same type: const sign = if (n < 0) { -1 } else { 1 };.
Counter.n: i32return value;Leaves the current function with the given value. A function whose return type is not void must return one; a bare return; is for void. In an async function it completes the future with the value.
Option::NoneOption::Some(T)mut name: Type = value;A mutable binding, reassignable after declaration - mutability is opt-in, const is the default. At module level it declares mutable global state. Before & it marks an exclusive reference or receiver instead.
mut c: Counterfor (mut i: i32 = 0; i < n; i++) { ... }
for (item in iterable) { ... }Two forms. The C-style for (init; condition; step) scopes its loop variable to the body. for (x in expr) iterates anything with next() -> Option<T>: an iterator, a range such as 0..n, an Array or Slice (their iter() is inserted for you), or a fixed-size array.
vfor (item in iterable) { ... }Separates the loop variable from the sequence in a for loop. The sequence is evaluated once; the loop lowers to loop { match (it.next()) { Some(x) => .., None => break } }.
mut c: Countertype struct TakeIter<I> {
inner: I;
remaining: u64;
}Adapter yielding at most remaining elements from inner.
type parameter ITakeIter.inner: Itype parameter ITakeIter.remaining: u64static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static TakeIter::new(inner: I, n: u64) -> TakeIter<I>(parameter) inner: Itype struct SkipIter<I> {
inner: I;
remaining: u64;
}Adapter that drops the first remaining elements of inner on the first next, then passes the rest through. remaining counts DOWN as elements are skipped; once it hits 0 the adapter is transparent.
SkipIter.inner: Itype parameter ISkipIter.remaining: u64static SkipIter::new(inner: I, n: u64) -> SkipIter<I>type struct MapIter<I, O> where I: Iterator {
inner: I;
}Adapter applying f to each element of inner. The input element type is the inner iterator's associated item I::Item; O is the mapped result (Output) type, the only element-type struct parameter needed.
type parameter Iwhere I: Iterator
type parameter OMapIter.inner: IMapIter::f: (I::Item) -> Otype parameter Ostatic MapIter::new(inner: I, f: (I::Item) -> O) -> MapIter<I, O>(parameter) f: (I::Item) -> Otype struct FilterIter<I> where I: Iterator {
inner: I;
}Adapter yielding only the elements of inner for which pred holds.
FilterIter.inner: IFilterIter::pred: (&I::Item) -> booleanstatic FilterIter::new(inner: I, pred: (&I::Item) -> boolean) -> FilterIter<I>(parameter) pred: (&I::Item) -> booleantype struct ChainIter<I, J> {
first: I;
second: J;
first_done: boolean;
}Adapter concatenating two iterators of the same element type: it drains first, then second. Both inner element types are pinned to the shared A by the where-bounds.
ChainIter.first: Itype parameter IChainIter.second: Jtype parameter JChainIter.first_done: booleanstatic ChainIter::new(first: I, second: J) -> ChainIter<I, J>(parameter) first: I(parameter) second: Jtype struct EnumerateIter<I> {
inner: I;
index: u64;
}Adapter pairing each element of inner with its 0-based index. The element type is the inner iterator's associated item I::Item; the yielded item is Pair<u64, I::Item>.
EnumerateIter.inner: Itype parameter IEnumerateIter.index: u64static EnumerateIter::new(inner: I) -> EnumerateIter<I>type struct ZipIter<I, J> {
first: I;
second: J;
}Adapter pairing two iterators positionally, yielding Pair<A, O> until either side runs out. Chain-shaped: the element types A (from I) and O (from J) live only in the impl where-bounds, not as struct parameters, so the receiver type only mentions the two inner iterators.
ZipIter.first: Itype parameter IZipIter.second: Jtype parameter Jstatic ZipIter::new(first: I, second: J) -> ZipIter<I, J>import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
Iterator::next(mut &this) -> Option<This::Item>Advance the sequence and return the next value, or None when exhausted. Calling next again after None may return None forever or may panic; implementations should document which.
xtype parameter TIterator::count(mut &this) -> u64Number of remaining elements. The default walks the iterator to count, consuming it. Implementations with O(1) knowledge of their length should override.
std::core::iterIterator::fold<Acc>(mut &this, initial: Acc, f: (Acc, This::Item) -> Acc) -> AccReduce the sequence to a single value. initial is the starting accumulator; f folds each element into it.
MapIter::f: (I::Item) -> OIterator::for_each(mut &this, f: (This::Item) -> void) -> voidCall f on each element, discarding the results. The natural way to consume an iterator purely for its side effects.
Iterator::take(this, n: u64) -> TakeIter<This>Yield at most the first n elements, then stop.
Iterator::skip(this, n: u64) -> SkipIter<This>Discard the first n elements, then yield the rest. An iterator with fewer than n elements is drained and yields nothing.
Iterator::map<B>(this, f: (This::Item) -> B) -> MapIter<This, B>Transform each element with f, yielding the results. f must be a non-capturing function (a plain fn or a non-capturing lambda).
Iterator::filter(this, pred: (&This::Item) -> boolean) -> FilterIter<This>Yield only the elements for which pred returns true. pred must be a non-capturing function. It BORROWS each element: the element it keeps is the one yielded, so it cannot also be handed to pred.
FilterIter::pred: (&I::Item) -> booleantrueThe boolean literal. Booleans are a distinct 1-byte type, not interchangeable with integers; if and while conditions must be boolean.
Iterator::chain<J>(this, other: J) -> ChainIter<This, J>Yield every element of this, then every element of other. other must be an Iterator with the same Item type - the shared element type is enforced by ChainIter's impl bounds.
Iterator::enumerate(this) -> EnumerateIter<This>Yield (index, value) pairs, the index counting up from 0 as a u64. The pair is Pair<u64, Item>: p.first is the index, p.second the element. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
EnumerateIter.index: u64type struct Pair<A, B> {
first: A;
second: B;
}Pair<A, B>: an owned two-element tuple.
std::collections::pairIterator::zip<J>(this, other: J) -> ZipIter<This, J>Yield pairs (a, b) drawing a from this and b from other, stopping as soon as either iterator is exhausted. The pair is Pair<Item, B> where B is other's element type: p.first comes from this, p.second from other. (Cryo has no heterogeneous tuple literal, so Pair is the element type.)
Iterator::any(mut &this, pred: (This::Item) -> boolean) -> booleanTrue if pred holds for at least one element. Short-circuits on the first match; consumes elements up to it.
Iterator::all(mut &this, pred: (This::Item) -> boolean) -> booleanTrue if pred holds for every element. Short-circuits on the first failure; vacuously true for an empty iterator.
Iterator::find(mut &this, pred: (&This::Item) -> boolean) -> Option<This::Item>The first element for which pred holds, or None. Consumes elements up to and including the match. pred borrows each element, since the one it accepts is returned.
Iterator::min(mut &this) -> Option<This::Item>
where This::Item: OrdThe smallest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the FIRST minimal element wins (only a strictly smaller element displaces the running best), so min and max of equal elements differ.
Iterator::max(mut &this) -> Option<This::Item>
where This::Item: OrdThe largest element by Ord, or None for an empty iterator. Consumes the iterator. On ties the LAST maximal element wins (an equal-or-greater element displaces the running best), the mirror of min.
mut it: implement Iterator<i32>-> implement Trait<T>An opaque type: some one concrete type that implements the trait, without naming it. The compiler infers the real type and uses it everywhere; callers see only the trait's methods. How the stdlib returns iterators without exposing their engines.
language referencetype struct Range<T> {
start: T;
end: T;
}static Range::new(start: T, end: T) -> Range<T>type parameter Atype parameter Jwhere J: Iterator
type parameter Twhere T: Copy
type trait Copy {}Types whose values can be duplicated by a bitwise copy. Integers, floats, pointers, and pure-POD structs qualify; anything that owns resources (heap storage, file handles, refcount) does not.
std::core::markertype parameter Twhere T: Clone
type parameter Kwhere K: Copy
type parameter Vwhere V: Copy
type struct HashMapIter<K, V> {
buckets: Entry<K, V>**;
bucket_count: u64;
bucket_index: u64;
current: Entry<K, V>*;
}type parameter Ktype parameter Vtype struct KeysRefIter<K, V> {
buckets: Entry<K, V>**;
bucket_count: u64;
bucket_index: u64;
current: Entry<K, V>*;
}type struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strtype struct SplitIter {
bytes: u8*;
length: u64;
sep_bytes: u8*;
sep_length: u64;
pos: u64;
done: boolean;
}Lazy iterator over the pieces of a Str separated by a byte sequence. Yields borrowed Str views; see Str::split. Borrows from the source Str, which must outlive the iterator.
type struct Chars {
bytes: u8*;
length: u64;
pos: u64;
}Lazy UTF-8 scalar iterator over a Str; see Str::chars. Borrows from the source Str, which must outlive the iterator.
type struct CharIndices {
bytes: u8*;
length: u64;
pos: u64;
}Lazy (byte_offset, scalar) iterator over a Str; see Str::char_indices. Borrows from the source Str. Public for the same cross-module reason as Chars.
type parameter Twhere T: Step
type trait Step : Ord {
successor(&this) -> This;
}type struct RangeInclusive<T> {
start: T;
end: T;
exhausted: boolean;
}type struct SliceIter<T> {
ptr: T*;
remaining: u64;
}type struct DirEntry {
entry_name: String;
dtype: u8;
}One entry returned by ReadDir. Owns its name; drop releases it.
type struct ReadDir {
dirp: void*;
base: String;
}Forward iterator over the entries of a directory. Yields owned DirEntry values, skipping . and ... Closes the underlying DIR* on drop. Order is filesystem-defined.