rok::core::iter
Iterator + IntoIterator + FromIterator (stdlib spec 2.7).
for pat in xs desugars to
let it = xs.into_iter();
loop { match it.next() { v: T => { let pat = v; body } none => break } }
(integer ranges and arrays keep a direct counting loop).
next takes ref self (2.7.1): an iterator's state lives in its
fields, written back into the caller's binding after each call.
Structs
Map
pub struct Map<IFilter
pub struct Filter<I>Trait implementations 2
impl<I: Iterator> Iterator for Filter<I>impl<I: DoubleEndedIterator> DoubleEndedIterator for Filter<I>
Enumerate
pub struct Enumerate<I>Trait implementations 3
impl<I: Iterator> Iterator for Enumerate<I>impl<I: ExactSizeIterator> ExactSizeIterator for Enumerate<I>impl<I: DoubleEndedIterator + ExactSizeIterator> DoubleEndedIterator for Enumerate<I>
Zip
pub struct Zip<IChain
pub struct Chain<IStepBy
pub struct StepBy<I>Trait implementations 3
impl<I: Iterator> Iterator for StepBy<I>impl<I: ExactSizeIterator> ExactSizeIterator for StepBy<I>impl<I: DoubleEndedIterator + ExactSizeIterator> DoubleEndedIterator for StepBy<I>
Rev
pub struct Rev<I>Trait implementations 3
impl<I: DoubleEndedIterator> Iterator for Rev<I>impl<I: DoubleEndedIterator> DoubleEndedIterator for Rev<I>impl<I: DoubleEndedIterator + ExactSizeIterator> ExactSizeIterator for Rev<I>
Flatten
pub struct Flatten<I>flatten: cur is the inner iterator being drained.
Trait implementations 1
impl<I: Iterator> Iterator for Flatten<I> where I::Item: IntoIterator
FlatMap
pub struct FlatMap<Iflat_map: cur is the inner iterator being drained.
Peekable
pub struct Peekable<I>pub const fn peek(ref self) -> I::Item | noneThe next item, left in place for the following
next.
Trait implementations 1
impl<I: Iterator> Iterator for Peekable<I>
Take
pub struct Take<I>Trait implementations 3
impl<I: Iterator> Iterator for Take<I>impl<I: ExactSizeIterator> ExactSizeIterator for Take<I>impl<I: DoubleEndedIterator + ExactSizeIterator> DoubleEndedIterator for Take<I>
Skip
pub struct Skip<I>Trait implementations 3
impl<I: Iterator> Iterator for Skip<I>impl<I: ExactSizeIterator> ExactSizeIterator for Skip<I>impl<I: DoubleEndedIterator + ExactSizeIterator> DoubleEndedIterator for Skip<I>
GenIter
pub struct GenIter<T>Trait implementations 1
impl<T> Iterator for GenIter<T>
TryGenIter
pub struct TryGenIter<TA throwing generator (yield fn f() throws (E) -> T): the error
surfaces at next (refs-lang 4.14.10), so a loop over it throws and
must be covered: try for x in g { .. }.
Traits
Iterator
pub trait Iteratortype Itemfn next(ref self) -> Item | noneconst fn map<U>(self, f: fn(Item) -> U) -> Map<SelfApply
fto each item.const fn filter(self, pred: fn(Item) -> bool) -> Filter<Self>Keep the items
predaccepts.const fn enumerate(self) -> Enumerate<Self>(index, item)pairs.const fn zip<J: Iterator>(self, other: J) -> Zip<SelfPairs of this iterator's and
other's items, until either ends.const fn chain<J: Iterator<Item = Item>>(self, other: J) -> Chain<SelfThis iterator's items, then
other's (with the same item type).const fn take(self, n: usize) -> Take<Self>At most the first
nitems.const fn skip(self, n: usize) -> Skip<Self>All but the first
nitems.const fn step_by(self, step: usize) -> StepBy<Self>Every
stepth item, starting with the first (step> 0).const fn rev(self) -> Rev<Self>The items back to front (
DoubleEndedIteratoronly, 2.7.9).const fn flatten(self) -> Flatten<Self> where Item: IntoIteratorThe items of each item (each item is
IntoIterator).const fn flat_map<U: IntoIterator>(self, f: fn(Item) -> U) -> FlatMap<SelfThe items of each
f(item)(anIntoIterator).const fn peekable(self) -> Peekable<Self>An iterator that can look at its next item without taking it.
const fn count(self) -> usizeconst fn sum(self) -> Item where Item: Add<Output = Item> + Zero { let acc = Item::zero(); for x in self { acc += x; } acc } /// The items multiplied; `1` for none. const fn product(self) -> Item where Item: Mul<Output = Item> + One { let acc = Item::one(); for x in self { acc *= x; } acc } const fn fold<B>(self, init: B, f: fn(B, Item) -> B) -> B { let acc = init; for x in self { acc = f(acc, x); } acc } /// The items combined left to right with `f`; `none` for none. const fn reduce(self, f: fn(Item, Item) -> Item) -> Item | none { let acc: Item | none = none; for x in self { acc = if let a: Item = acc { f(a, x) } else { x }; } acc } const fn any(self, pred: fn(Item) -> bool) -> bool { for x in self { if pred(x) { return true; } } false } const fn all(self, pred: fn(Item) -> bool) -> bool { for x in self { if !pred(x) { return false; } } true } const fn find(self, pred: fn(Item) -> bool) -> Item | none { for x in self { if pred(x) { return x; } } none } const fn position(self, pred: fn(Item) -> bool) -> usize | none { let i: usize = 0; for x in self { if pred(x) { return i; } i += 1; } none } const fn min(self) -> Item | none where Item: Ord { let best: Item | none = none; for x in self { match best { b: Item => { if x.cmp(b).is_lt() { best = x; } } none => { best = x; } } } best } const fn max(self) -> Item | none where Item: Ord { let best: Item | none = none; for x in self { match best { b: Item => { if x.cmp(b).is_gt() { best = x; } } none => { best = x; } } } best } /// The item with the smallest `key` (the first of equals). const fn min_by_key<K: Ord>(self, key: fn(Item) -> K) -> Item | none { let best: Item | none = none; let best_key: K | none = none; for x in self { let k = key(x); match best_key { b: K => { if k.cmp(b).is_lt() { best = x; best_key = k; } } none => { best = x; best_key = k; } } } best } /// The item with the largest `key` (the last of equals). const fn max_by_key<K: Ord>(self, key: fn(Item) -> K) -> Item | none { let best: Item | none = none; let best_key: K | none = none; for x in self { let k = key(x); match best_key { b: K => { if !k.cmp(b).is_lt() { best = x; best_key = k; } } none => { best = x; best_key = k; } } } best } const fn last(self) -> Item | none { let last: Item | none = none; for x in self { last = x; } last } /// The `n`th remaining item (0-based), consuming the ones before it. const fn nth(ref self, n: usize) -> Item | none { for i in 0..n { self.next()?; } self.next() } const fn for_each(self, f: fn(Item)) { for x in self { f(x); } } /// Gather the items into a `FromIterator` collection (the slot's /// type picks it: `let v: List<i32> = it.collect();`). const fn collect<C: FromIterator<Item>>(self) -> C { C::from_iter(self) }The items added up;
0for none.
DoubleEndedIterator
pub trait DoubleEndedIterator: IteratorAn iterator that can also step from the back (2.7.9).
fn next_back(ref self) -> Item | noneconst fn rfold<B>(self, init: B, f: fn(B, Self::Item) -> B) -> Bfoldfrom the back.const fn rfind(self, pred: fn(Self::Item) -> bool) -> Self::Item | noneThe last item
predaccepts, searching from the back.
ExactSizeIterator
pub trait ExactSizeIterator: IteratorAn iterator that knows how many items remain (2.7.10).
fn len(self) -> usize
IntoIterator
pub trait IntoIteratortype IntoIter: Iterator<Item = Item>type Itemfn into_iter(self) -> IntoIter
FromIterator
pub trait FromIterator<A>A collection buildable from an iterator (collect, 2.9.9).
fn from_iter<I: IntoIterator<Item = A>>(it: I) -> Self