pub trait Iterator {
type Item<'a>
where
Self: 'a;
Show 22 methods
fn next(&mut self) -> Option<Self::Item<'_>>;
fn size_hint(&self) -> (usize, Option<usize>) { ... }
fn advance_by(&mut self, n: usize) -> Result<(), usize> { ... }
fn nth(&mut self, n: usize) -> Option<Self::Item<'_>> { ... }
fn map<O, F>(self, f: F) -> Map<Self, F> ⓘ
where
Self: Sized,
F: FnMut(Self::Item<'_>) -> O,
{ ... }
fn touch<F>(self, f: F) -> Touch<Self, F>
where
Self: Sized,
F: FnMut(&mut Self::Item<'_>),
{ ... }
fn filter<F>(self, f: F) -> Filter<Self, F>
where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
{ ... }
fn step_by(self, step: usize) -> StepBy<Self>
where
Self: Sized,
{ ... }
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>
where
Self: Sized,
U: IntoIterator,
U::IntoIter: for<'a> Iterator<Item<'a> = Self::Item<'a>>,
{ ... }
fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
where
Self: Sized,
U: IntoIterator,
{ ... }
fn enumerate(self) -> Enumerate<Self>
where
Self: Sized,
{ ... }
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
{ ... }
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
{ ... }
fn skip(self, n: usize) -> Skip<Self>
where
Self: Sized,
{ ... }
fn take(self, n: usize) -> Take<Self>
where
Self: Sized,
{ ... }
fn all<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item<'_>) -> bool,
{ ... }
fn any<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item<'_>) -> bool,
{ ... }
fn find<F>(&mut self, f: F) -> Option<Self::Item<'_>>
where
F: FnMut(&Self::Item<'_>) -> bool,
{ ... }
fn count(self) -> usize
where
Self: Sized,
{ ... }
fn for_each<F>(self, f: F)
where
Self: Sized,
F: FnMut(Self::Item<'_>),
{ ... }
fn fold<T, F>(self, acc: T, f: F) -> T
where
Self: Sized,
F: FnMut(T, Self::Item<'_>) -> T,
{ ... }
fn scan<T, B, F>(self, acc: T, f: F) -> Scan<Self, T, F> ⓘ
where
Self: Sized,
F: FnMut(&mut T, Self::Item<'_>) -> Option<B>,
{ ... }
}
Expand description
A lending iterator, whose items may have their lifetimes tied to the individual borrow of the
iterator. This allows for things like yielding mutable references that overlap, with the
trade-off that there’s no generic collect
interface - the items of this iterator cannot
co-exist.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Get a hint as to the size of this iterator - the first value is a lower bound, second is an optional upper bound.
sourcefn nth(&mut self, n: usize) -> Option<Self::Item<'_>>
fn nth(&mut self, n: usize) -> Option<Self::Item<'_>>
Return the n
th element of the iterator
This does not rewind the iterator after completion, so repeatedly calling nth(0)
is
equivalent to calling next
sourcefn map<O, F>(self, f: F) -> Map<Self, F> ⓘwhere
Self: Sized,
F: FnMut(Self::Item<'_>) -> O,
fn map<O, F>(self, f: F) -> Map<Self, F> ⓘwhere
Self: Sized,
F: FnMut(Self::Item<'_>) -> O,
Take a closure which will take each value from the iterator, and yield a new value computed from it.
The result cannot reference the provided data, as such, this returns an iterator which also implements the non-lending core iterator
sourcefn touch<F>(self, f: F) -> Touch<Self, F>where
Self: Sized,
F: FnMut(&mut Self::Item<'_>),
fn touch<F>(self, f: F) -> Touch<Self, F>where
Self: Sized,
F: FnMut(&mut Self::Item<'_>),
Gain mutable access to each value in this iterator, then yield it to the next step. This allows altering each item without consuming it, preserving the lending nature or the iterator
sourcefn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
fn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
Execute a closure on each item in the iterator, returning true if it should be included, or false to skip it
sourcefn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Creates an iterator starting at the same point, but stepping by the given amount at each iteration
sourcefn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>where
Self: Sized,
U: IntoIterator,
U::IntoIter: for<'a> Iterator<Item<'a> = Self::Item<'a>>,
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>where
Self: Sized,
U: IntoIterator,
U::IntoIter: for<'a> Iterator<Item<'a> = Self::Item<'a>>,
Takes two iterators and creates a new iterator over both in sequence
sourcefn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>where
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>where
Self: Sized,
U: IntoIterator,
‘Zips up’ two iterators into a single iterator of pairs
sourcefn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Creates an iterator which gives the current iteration count as well as the next value
sourcefn skip_while<F>(self, f: F) -> SkipWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
Creates an iterator that skips elements based on a predicate
sourcefn take_while<F>(self, f: F) -> TakeWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool,
Creates an iterator that yields elements based on a predicate
sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Creates an iterator that skips the first n elements
sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner
sourcefn all<F>(&mut self, f: F) -> boolwhere
F: FnMut(Self::Item<'_>) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere
F: FnMut(Self::Item<'_>) -> bool,
Tests if every element of the iterator matches a predicate
sourcefn any<F>(&mut self, f: F) -> boolwhere
F: FnMut(Self::Item<'_>) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere
F: FnMut(Self::Item<'_>) -> bool,
Tests if any element of the iterator matches a predicate
sourcefn find<F>(&mut self, f: F) -> Option<Self::Item<'_>>where
F: FnMut(&Self::Item<'_>) -> bool,
fn find<F>(&mut self, f: F) -> Option<Self::Item<'_>>where
F: FnMut(&Self::Item<'_>) -> bool,
Searches for an element of an iterator that satisfies a predicate
sourcefn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere
Self: Sized,
Consume the iterator, counting the number of items and returning it
sourcefn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item<'_>),
fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item<'_>),
Execute a closure on each value of this iterator
sourcefn fold<T, F>(self, acc: T, f: F) -> Twhere
Self: Sized,
F: FnMut(T, Self::Item<'_>) -> T,
fn fold<T, F>(self, acc: T, f: F) -> Twhere
Self: Sized,
F: FnMut(T, Self::Item<'_>) -> T,
Execute a closure on each value of this iterator, with an additional ‘accumulator’ value passed to each call. The closure is expected to return the new value of the accumulator.
sourcefn scan<T, B, F>(self, acc: T, f: F) -> Scan<Self, T, F> ⓘwhere
Self: Sized,
F: FnMut(&mut T, Self::Item<'_>) -> Option<B>,
fn scan<T, B, F>(self, acc: T, f: F) -> Scan<Self, T, F> ⓘwhere
Self: Sized,
F: FnMut(&mut T, Self::Item<'_>) -> Option<B>,
Execute a closure on each value of this iterator, with an additional state value passed
via mutable reference to each call. The closure is expected to return the new value
for each step of the iterator, if the returned value is None
the iterator stops early.
The result cannot reference the provided data, as such, this returns an iterator which also implements the non-lending core iterator