pub trait Iterator {
type Item<'a>
where Self: 'a;
Show 22 methods
// Required method
fn next(&mut self) -> Option<Self::Item<'_>>;
// Provided methods
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> ⓘ
fn map<O, F>(self, f: F) -> Map<Self, F> ⓘ
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>
fn touch<F>(self, f: F) -> Touch<Self, F>
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>
fn filter<F>(self, f: F) -> Filter<Self, F>
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>
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter>
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>
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
Creates an iterator that skips elements based on a predicate
Sourcefn take_while<F>(self, f: F) -> TakeWhile<Self, F>
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
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 find<F>(&mut self, f: F) -> Option<Self::Item<'_>>
fn find<F>(&mut self, f: F) -> Option<Self::Item<'_>>
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 fold<T, F>(self, acc: T, f: F) -> T
fn fold<T, F>(self, acc: T, f: F) -> 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> ⓘ
fn scan<T, B, F>(self, acc: T, f: F) -> Scan<Self, T, F> ⓘ
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
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.