docs

core::iter

이 페이지의 내용

API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.

Iterator + IntoIterator + FromIterator.

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: an iterator's state lives in its fields, written back into the caller's binding after each call.

Structs

ChainSource

pub struct Chain<I, J>

The iterator chain returns: every item of the first, then of the second.

Trait implementations 3

ChunksSource

pub struct Chunks<I>

The iterator chunks returns: lists of size items, the last one shorter when the items run out.

Trait implementations 3

CombinationsSource

pub struct Combinations<T>

The iterator combinations returns: each choice of k items as a list.

Trait implementations 2
  • impl<T> Debug for Combinations<T>
  • impl<T> Iterator for Combinations<T>

CycleSource

pub struct Cycle<I>

The iterator cycle returns: the items over and over; empty if the source is.

Trait implementations 2

EnumerateSource

pub struct Enumerate<I>

The iterator enumerate returns: (index, item) pairs from the start index.

Trait implementations 4

FilterSource

pub struct Filter<I>

The iterator filter returns: the items pred accepts, in order.

Trait implementations 3

FlatMapSource

pub struct FlatMap<I, U>

flat_map: cur is the inner iterator being drained.

Trait implementations 2

FlattenSource

pub struct Flatten<I>

flatten: cur is the inner iterator being drained.

Trait implementations 2

InspectIterSource

pub struct InspectIter<I>

inspect's adapter (Inspect is the reflection trait).

Trait implementations 4

MapSource

pub struct Map<I, U>

The iterator map returns: f of each item.

Trait implementations 4

PairwiseSource

pub struct Pairwise<I>

The iterator pairwise returns: each item with the next.

Trait implementations 2

PeekableSource

pub struct Peekable<I>

The iterator peekable returns: peek looks at the next item without taking it.

  • pub const fn peek(ref self) -> I::Item | none§

    Source

    The next item, left in place for the following next.

Trait implementations 2

PermutationsSource

pub struct Permutations<T>

The iterator permutations returns: each ordering of k items as a list.

Trait implementations 2
  • impl<T> Debug for Permutations<T>
  • impl<T> Iterator for Permutations<T>

RevSource

pub struct Rev<I>

The iterator rev returns: the items from the back.

Trait implementations 4

ScanSource

pub struct Scan<I, S>

The iterator scan returns: each running state of f.

Trait implementations 3

SkipSource

pub struct Skip<I>

The iterator skip returns: all but the first n items.

Trait implementations 4

SkipWhileSource

pub struct SkipWhile<I>

The iterator skip_while returns: items from the first that pred rejects on.

Trait implementations 2

StepBySource

pub struct StepBy<I>

The iterator step_by returns: the first item, then every stepth.

Trait implementations 4

TakeSource

pub struct Take<I>

The iterator take returns: at most the first n items.

Trait implementations 4

TakeWhileSource

pub struct TakeWhile<I>

The iterator take_while returns: items up to the first that pred rejects.

Trait implementations 2

WindowsSource

pub struct Windows<I>

The iterator windows returns: every run of size consecutive items, overlapping, as lists.

Trait implementations 2

ZipSource

pub struct Zip<I, J>

The iterator zip returns: pairs of items; ends with the shorter side.

Trait implementations 4

FromResultsSource

pub struct FromResults<I, T, E>

The TryIterator iter::from_results returns: an Err item is thrown.

Trait implementations 2

InfallibleSource

pub struct Infallible<I, E>

The TryIterator iter::infallible returns: the items, never an error.

Trait implementations 2

MapErrSource

pub struct MapErr<I, E2>

The iterator map_err returns: each error passed through f.

Trait implementations 2

ResultsSource

pub struct Results<I>

results's adapter.

Trait implementations 2

TryChainSource

pub struct TryChain<I, J>

The iterator TryIterator::chain returns: every item of the first, then of the second.

Trait implementations 2

TryChunksSource

pub struct TryChunks<I>

A throw drops the chunk being built.

Trait implementations 2

TryEnumerateSource

pub struct TryEnumerate<I>

The iterator TryIterator::enumerate returns: (index, item) pairs from 0.

Trait implementations 2

TryFilterSource

pub struct TryFilter<I>

The iterator TryIterator::filter returns: the items pred accepts.

Trait implementations 2

TryFlatMapSource

pub struct TryFlatMap<I, U>

flat_map: cur is the inner iterator being drained.

Trait implementations 2

TryFromFnSource

pub struct TryFromFn<T, E>

The TryIterator iter::try_from_fn returns: each item is f().

Trait implementations 2

TryInspectSource

pub struct TryInspect<I>

The iterator TryIterator::inspect returns: the items, each shown to f first.

Trait implementations 2

TryMapSource

pub struct TryMap<I, U>

The iterator TryIterator::map returns: f of each item.

Trait implementations 2

TryPeekableSource

pub struct TryPeekable<I>

The iterator TryIterator::peekable returns: the items, with a look at the next.

  • pub const fn peek(ref self) throws (I::Error) -> I::Item | none§

    Source

    The next item, left in place for the following next; a throw leaves nothing peeked.

Trait implementations 2

TryScanSource

pub struct TryScan<I, S>

The iterator TryIterator::scan returns: f of a running state and each item.

Trait implementations 2

TrySkipSource

pub struct TrySkip<I>

The iterator TryIterator::skip returns: all but the first n items.

Trait implementations 2

TrySkipWhileSource

pub struct TrySkipWhile<I>

The iterator TryIterator::skip_while returns: items from the first pred rejects.

Trait implementations 2

TryStepBySource

pub struct TryStepBy<I>

The iterator TryIterator::step_by returns: the first item, then every stepth.

Trait implementations 2

TryTakeSource

pub struct TryTake<I>

The iterator TryIterator::take returns: at most the first n items.

Trait implementations 2

TryTakeWhileSource

pub struct TryTakeWhile<I>

The iterator TryIterator::take_while returns: items while pred accepts them.

Trait implementations 2

TryZipSource

pub struct TryZip<I, J>

The iterator TryIterator::zip returns: pairs of items; ends with the shorter side.

Trait implementations 2

GenIterSource

pub struct GenIter<T>
Trait implementations 2

TryGenIterSource

pub struct TryGenIter<T, E>

A throwing generator (yield fn f() throws (E) -> T): a TryIterator whose next throws what the body throws, stepped with try for x in g { .. }.

Trait implementations 2
  • impl<T, E> Debug for TryGenIter<T, E>
  • impl<T, E> TryIterator for TryGenIter<T, E>

Traits

TryIteratorSource

pub trait TryIterator

An iterator whose next can fail: an item, none at the end, or a thrown Error. What a next after a throw does is the type's documented choice: it may go on (fs::Walk) or end (fs::ReadDir).

try for x in it { .. } steps it: the try covers the iterable and each next, not the body. The adapters' functions may throw Error (a non-throwing function fits too); map_err changes it.

  • type Item§

    Source
  • type Error§

    Source
  • fn next(ref self) throws (Error) -> Item | none§

    Source

    The next item, or none once the iterator is done.

  • const fn map<U>(self, f: fn(Item) throws (Error) -> U) -> TryMap<Self, U>§

    Source

    Apply f to each item.

  • const fn filter(self, pred: fn(Item) throws (Error) -> bool) -> TryFilter<Self>§

    Source

    Keep the items pred accepts.

  • const fn map_err<E2>(self, f: fn(Error) -> E2) -> MapErr<Self, E2>§

    Source

    The same items, each error passed through f: the only way to change Error (.map_err(|e| -> any Error { e }) erases it).

  • const fn enumerate(self, start: usize = 0usize) -> TryEnumerate<Self>§

    Source

    (index, item) pairs, the index counting from start.

  • const fn zip<J: IntoIterator>(self, other: J) -> TryZip<Self, J::IntoIter>§

    Source

    Pairs of this iterator's items and a plain iterator's, until either ends.

  • const fn chain<J: TryIterator<Item = Item, Error = Error>>(self, other: J) -> TryChain<Self, J>§

    Source

    This iterator's items, then other's.

  • const fn take(self, n: usize) -> TryTake<Self>§

    Source

    At most the first n items.

  • const fn skip(self, n: usize) -> TrySkip<Self>§

    Source

    All but the first n items.

  • const fn step_by(self, step: usize) -> TryStepBy<Self>§

    Source

    Every stepth item, starting with the first (step > 0).

  • const fn take_while(self, pred: fn(Item) throws (Error) -> bool) -> TryTakeWhile<Self>§

    Source

    The items before the first one pred rejects.

  • const fn skip_while(self, pred: fn(Item) throws (Error) -> bool) -> TrySkipWhile<Self>§

    Source

    The items from the first one pred rejects on.

  • const fn flat_map<U: IntoIterator>(self, f: fn(Item) throws (Error) -> U) -> TryFlatMap<Self, U>§

    Source

    The items of each f(item) (a plain IntoIterator).

  • const fn scan<S>(self, init: S, f: fn(S, Item) throws (Error) -> S) -> TryScan<Self, S>§

    Source

    The running state: f(init, x0), then f of that and x1, ...

  • const fn inspect(self, f: fn(Item) throws (Error)) -> TryInspect<Self>§

    Source

    The same items, each passed to f first.

  • const fn peekable(self) -> TryPeekable<Self>§

    Source

    An iterator that can look at its next item without taking it.

  • const fn chunks(self, size: usize) -> TryChunks<Self>§

    Source

    Lists of size items in order, the last one shorter (size > 0).

  • const fn results(self) -> Results<Self>§

    Source

    A plain iterator of Results: each error becomes a Result::Err item and stepping goes on, so a source that ends after an error gives that Err last.

  • const fn collect<C: FromIterator<Item>>(self) throws (Error) -> C§

    Source

    Gather the items into a FromIterator collection; the first error stops it and is thrown.

  • const fn count(self) throws (Error) -> usize§

    Source

    The number of items left, consuming them.

  • const fn last(self) throws (Error) -> Item | none§

    Source

    The last item.

  • const fn nth(ref self, n: usize) throws (Error) -> Item | none§

    Source

    The nth remaining item (0-based), consuming the ones before it.

  • const fn fold<B>(self, init: B, f: fn(B, Item) throws (Error) -> B) throws (Error) -> B§

    Source

    Every item folded into init by f, in order.

  • const fn for_each(self, f: fn(Item) throws (Error)) throws (Error)§

    Source

    Calls f on every item, in order.

  • const fn reduce(self, f: fn(Item, Item) throws (Error) -> Item) throws (Error) -> Item | none§

    Source

    The items combined left to right with f; none for none.

  • const fn any(self, pred: fn(Item) throws (Error) -> bool) throws (Error) -> bool§

    Source

    Whether pred accepts some item; stops at the first.

  • const fn all(self, pred: fn(Item) throws (Error) -> bool) throws (Error) -> bool§

    Source

    Whether pred accepts every item; stops at the first refusal.

  • const fn find(self, pred: fn(Item) throws (Error) -> bool) throws (Error) -> Item | none§

    Source

    The first item pred accepts.

  • const fn position(self, pred: fn(Item) throws (Error) -> bool) throws (Error) -> usize | none§

    Source

    The index of the first item pred accepts.

  • const fn partition(self, pred: fn(Item) throws (Error) -> bool) throws (Error) -> (List<Item>, List<Item>)§

    Source

    The items pred accepts, then the rest, each in order.

  • const fn sum(self) throws (Error) -> Item where Item: Add<Output = Item> + Zero§

    Source

    The items added up; 0 for none.

  • const fn product(self) throws (Error) -> Item where Item: Mul<Output = Item> + One§

    Source

    The items multiplied; 1 for none.

  • const fn min(self) throws (Error) -> Item | none where Item: Ord§

    Source

    The smallest item (the first of equals).

  • const fn max(self) throws (Error) -> Item | none where Item: Ord§

    Source

    The largest item (the last of equals).

  • const fn min_by_key<K: Ord>(self, key: fn(Item) throws (Error) -> K) throws (Error) -> Item | none§

    Source

    The item with the smallest key (the first of equals).

  • const fn max_by_key<K: Ord>(self, key: fn(Item) throws (Error) -> K) throws (Error) -> Item | none§

    Source

    The item with the largest key (the last of equals).

IteratorSource

pub trait Iterator

A source of items, one per next call; none ends it. The adapters below are lazy: nothing runs until the iterator is consumed.

  • type Item§

    Source
  • fn next(ref self) -> Item | none§

    Source

    The next item, or none once the iterator is done.

  • const fn map<U>(self, f: fn(Item) -> U) -> Map<Self, U>§

    Source

    Apply f to each item.

  • const fn filter(self, pred: fn(Item) -> bool) -> Filter<Self>§

    Source

    Keep the items pred accepts.

  • const fn enumerate(self, start: usize = 0usize) -> Enumerate<Self>§

    Source

    (index, item) pairs, the index counting from start.

  • const fn zip<J: IntoIterator>(self, other: J) -> Zip<Self, J::IntoIter>§

    Source

    Pairs of this iterator's and other's items, until either ends.

  • const fn chain<J: IntoIterator<Item = Item>>(self, other: J) -> Chain<Self, J::IntoIter>§

    Source

    This iterator's items, then other's (with the same item type).

  • const fn take(self, n: usize) -> Take<Self>§

    Source

    At most the first n items.

  • const fn skip(self, n: usize) -> Skip<Self>§

    Source

    All but the first n items.

  • const fn step_by(self, step: usize) -> StepBy<Self>§

    Source

    Every stepth item, starting with the first. Panics when step is 0.

  • const fn rev(self) -> Rev<Self>§

    Source

    The items back to front (DoubleEndedIterator only).

  • const fn flatten(self) -> Flatten<Self> where Item: IntoIterator§

    Source

    The items of each item (each item is IntoIterator).

  • const fn flat_map<U: IntoIterator>(self, f: fn(Item) -> U) -> FlatMap<Self, U>§

    Source

    The items of each f(item) (an IntoIterator).

  • const fn peekable(self) -> Peekable<Self>§

    Source

    An iterator that can look at its next item without taking it.

  • const fn take_while(self, pred: fn(Item) -> bool) -> TakeWhile<Self>§

    Source

    The items before the first one pred rejects; that one is used up and nothing after it is taken.

  • const fn skip_while(self, pred: fn(Item) -> bool) -> SkipWhile<Self>§

    Source

    The items from the first one pred rejects on.

  • const fn scan<S>(self, init: S, f: fn(S, Item) -> S) -> Scan<Self, S>§

    Source

    The running state: f(init, x0), then f of that and x1, and so on (fold that yields each step).

  • const fn inspect(self, f: fn(Item)) -> InspectIter<Self>§

    Source

    The same items, each passed to f first (for side effects).

  • const fn cycle(self) -> Cycle<Self>§

    Source

    The items over and over, restarting from a copy of this iterator; empty if it is empty.

  • const fn chunks(self, size: usize) -> Chunks<Self>§

    Source

    Lists of size items in order, the last one shorter when the items run out (size > 0).

  • const fn windows(self, size: usize) -> Windows<Self>§

    Source

    Lists of size consecutive items, sliding by one (size > 0); nothing when there are fewer than size items.

  • const fn exact_len(self) -> usize | none§

    Source

    The number of items left when that is known without stepping (no item is computed), else none. count uses it.

  • const fn count(self) -> usize§

    Source

    The number of items left: exact_len when known, else stepped.

  • const fn sum(self) -> Item where Item: Add<Output = Item> + Zero§

    Source

    The items added up; 0 for none. f32 / f64 items are summed pairwise: blocks of 128 items, each added left to right, and the block sums combined as a binary counter merges equal-sized partial sums, the rest added last to first. The order depends only on the item count, so the result is the same on every target.

  • const fn product(self) -> Item where Item: Mul<Output = Item> + One§

    Source

    The items multiplied; 1 for none.

  • const fn fold<B>(self, init: B, f: fn(B, Item) -> B) -> B§

    Source

    Every item folded into init by f, in order.

  • const fn try_fold<B, E>(self, init: B, f: fn(B, Item) throws (E) -> B) throws (E) -> B§

    Source

    fold with a throwing f: the first error stops the loop and is thrown.

  • const fn try_for_each<E>(self, f: fn(Item) throws (E)) throws (E)§

    Source

    for_each with a throwing f: the first error stops the loop and is thrown.

  • const fn partition(self, pred: fn(Item) -> bool) -> (List<Item>, List<Item>)§

    Source

    The items pred accepts, then the rest, each in order.

  • const fn unzip<A, B>(self) -> (List<A>, List<B>) where Self: Iterator<Item = (A, B)>§

    Source

    The pairs split into a list of firsts and a list of seconds.

  • const fn reduce(self, f: fn(Item, Item) -> Item) -> Item | none§

    Source

    The items combined left to right with f; none for none.

  • const fn any(self, pred: fn(Item) -> bool) -> bool§

    Source

    Whether pred accepts some item; stops at the first.

  • const fn all(self, pred: fn(Item) -> bool) -> bool§

    Source

    Whether pred accepts every item; stops at the first refusal.

  • const fn find(self, pred: fn(Item) -> bool) -> Item | none§

    Source

    The first item pred accepts.

  • const fn position(self, pred: fn(Item) -> bool) -> usize | none§

    Source

    The index of the first item pred accepts.

  • const fn min(self) -> Item | none where Item: PartialOrd§

    Source

    The smallest item (the first of equals). An item unordered with itself (a float NaN) is the result: NaN propagates, as IEEE 754 minimum and NumPy min.

  • const fn max(self) -> Item | none where Item: PartialOrd§

    Source

    The largest item (the last of equals). An item unordered with itself (a float NaN) is the result: NaN propagates, as IEEE 754 maximum and NumPy max.

  • const fn min_by_key<K: Ord>(self, key: fn(Item) -> K) -> Item | none§

    Source

    The item with the smallest key (the first of equals).

  • const fn max_by_key<K: Ord>(self, key: fn(Item) -> K) -> Item | none§

    Source

    The item with the largest key (the last of equals).

  • const fn last(self) -> Item | none§

    Source

    The last item.

  • const fn nth(ref self, n: usize) -> Item | none§

    Source

    The nth remaining item (0-based), consuming the ones before it.

  • const fn for_each(self, f: fn(Item))§

    Source

    Calls f on every item, in order.

  • const fn collect<C: FromIterator<Item> = List<Item>>(self) -> C§

    Source

    Gather the items into a FromIterator collection: the slot's type picks it (let s: Set<i32> = it.collect();), a List when nothing does.

  • const fn to_list(self) -> List<Item>§

    Source

    The items in a new List.

  • const fn to_set(self) -> Set<Item> where Item: Hash§

    Source

    The items in a new Set (first occurrences, in order).

  • const fn to_dict<K: Hash, V>(self) -> Dict<K, V> where Self: Iterator<Item = (K, V)>§

    Source

    The (key, value) items in a new Dict; a later key's value replaces an earlier one's.

  • const fn sorted(self, reverse: bool = false) -> List<Item> where Item: Ord§

    Source

    The items in a new sorted List, largest first when reverse. The sort is stable. Python: sorted(xs, reverse=...).

  • const fn sorted_by_key<K: Ord>(self, key: fn(Item) -> K, reverse: bool = false) -> List<Item>§

    Source

    The items in a new List sorted by key, largest key first when reverse; equal keys keep their order. Python: sorted(xs, key=f, reverse=...).

  • const fn sorted_by(self, cmp: fn(Item, Item) -> core::cmp::Ordering) -> List<Item>§

    Source

    The items in a new List sorted by cmp; equal items keep their order.

  • const fn counts(self) -> Dict<Item, usize> where Item: Hash§

    Source

    How often each item occurs, keyed in first-seen order. Python: collections.Counter(xs); most_common(n) on the result ranks them.

  • const fn group_by<K: Hash>(self, key: fn(Item) -> K) -> Dict<K, List<Item>>§

    Source

    The items grouped by key: each key, in first-seen order, with its items in order. Unlike Python's itertools.groupby, equal keys need not be adjacent.

  • const fn pairwise(self) -> Pairwise<Self>§

    Source

    Each item paired with the next: (x0, x1), (x1, x2), ..; nothing for fewer than two items.

  • const fn combinations(self, k: usize) -> Combinations<Item>§

    Source

    Every choice of k items in item order, as lists, in lexicographic order of positions. The items are gathered first. Python: itertools.combinations(xs, k).

  • const fn permutations(self, k: usize | none = none) -> Permutations<Item>§

    Source

    Every ordering of k distinct-position items (all items when k is none), as lists, in lexicographic order of positions. The items are gathered first. Python: itertools.permutations(xs, k).

DoubleEndedIteratorSource

pub trait DoubleEndedIterator: Iterator

An iterator that can also step from the back.

  • fn next_back(ref self) -> Item | none§

    Source

    The next item from the back, or none when the two ends meet.

  • const fn rfold<B>(self, init: B, f: fn(B, Self::Item) -> B) -> B§

    Source

    fold from the back.

  • const fn rfind(self, pred: fn(Self::Item) -> bool) -> Self::Item | none§

    Source

    The last item pred accepts, searching from the back.

ExactSizeIteratorSource

pub trait ExactSizeIterator: Iterator

An iterator that knows how many items remain.

  • fn len(self) -> usize§

    Source

    The number of items left.

IntoIteratorSource

pub trait IntoIterator

A value for can walk: into_iter turns it into an iterator.

FromIteratorSource

pub trait FromIterator<A>

A collection buildable from an iterator (collect).

  • fn from_iter<I: IntoIterator<Item = A>>(it: I) -> Self§

    Source

    A collection holding the items of it, in iteration order.

Functions

from_resultsSource

pub const fn from_results<T, E, I: IntoIterator<Item = Result<T, E>>>(it: I) -> FromResults<I::IntoIter, T, E>

A plain iterator of Results as a TryIterator: an Err item is thrown, then stepping goes on.

infallibleSource

pub const fn infallible<E, I: IntoIterator>(it: I) -> Infallible<I::IntoIter, E>

A plain iterator as a TryIterator that never throws, for an API that takes one: iter::infallible::<IoError>(names).

try_from_fnSource

pub const fn try_from_fn<T, E>(f: fn() throws (E) -> (T | none)) -> TryFromFn<T, E>

A TryIterator whose next calls f.