pub trait LendingIterator {
type Item<'a>
where Self: 'a;
Show 37 methods
// Required method
fn next(&mut self) -> Option<Self::Item<'_>>;
// Provided methods
fn size_hint(&self) -> (usize, Option<usize>) { ... }
fn count(self) -> usize
where Self: Sized { ... }
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> { ... }
fn nth(&mut self, n: usize) -> Option<Self::Item<'_>> { ... }
fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized { ... }
fn take(self, n: usize) -> Take<Self>
where Self: Sized { ... }
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized,
P: for<'a> FnMut(&Self::Item<'a>) -> bool { ... }
fn chain<I>(self, other: I) -> Chain<Self, I>
where Self: Sized,
for<'a> I: LendingIterator<Item<'a> = Self::Item<'a>> + 'a { ... }
fn zip<I>(self, other: I) -> Zip<Self, I>
where Self: Sized,
I: LendingIterator { ... }
fn map<F>(self, f: F) -> Map<Self, F>
where Self: Sized,
F: for<'a> SingleArgFnMut<Self::Item<'a>> { ... }
fn for_each<F>(self, f: F)
where Self: Sized,
F: FnMut(Self::Item<'_>) { ... }
fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized,
P: for<'a> FnMut(&Self::Item<'a>) -> bool { ... }
fn filter_map<F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized,
F: for<'a> SingleArgFnMut<Self::Item<'a>>,
for<'a> <F as SingleArgFnOnce<Self::Item<'a>>>::Output: OptionTrait { ... }
fn fold<B, F>(self, init: B, f: F) -> B
where Self: Sized,
F: FnMut(B, Self::Item<'_>) -> B { ... }
fn cloned<T>(self) -> Cloned<Self>
where Self: Sized,
for<'a> Self::Item<'a>: Deref<Target = T>,
T: Clone { ... }
fn enumerate(self) -> Enumerate<Self>
where Self: Sized { ... }
fn skip(self, n: usize) -> Skip<Self>
where Self: Sized { ... }
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized,
P: for<'a> FnMut(&Self::Item<'a>) -> bool { ... }
fn by_ref(&mut self) -> &mut Self
where Self: Sized { ... }
fn all<P>(&mut self, predicate: P) -> bool
where P: FnMut(Self::Item<'_>) -> bool { ... }
fn any<P>(&mut self, predicate: P) -> bool
where P: FnMut(Self::Item<'_>) -> bool { ... }
fn is_partitioned<P>(self, predicate: P) -> bool
where Self: Sized,
P: FnMut(Self::Item<'_>) -> bool { ... }
fn find<P>(&mut self, predicate: P) -> Option<Self::Item<'_>>
where P: FnMut(&Self::Item<'_>) -> bool { ... }
fn find_map<B, F>(&mut self, f: F) -> Option<B>
where F: FnMut(Self::Item<'_>) -> Option<B> { ... }
fn position<P>(&mut self, predicate: P) -> Option<usize>
where P: FnMut(Self::Item<'_>) -> bool { ... }
fn cmp<I>(self, other: I) -> Ordering
where I: for<'a> LendingIterator<Item<'a> = Self::Item<'a>>,
for<'a> Self::Item<'a>: Ord,
Self: Sized { ... }
fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
where Self: Sized,
I: LendingIterator,
F: FnMut(Self::Item<'_>, I::Item<'_>) -> Ordering { ... }
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialOrd<I::Item<'a>>,
Self: Sized { ... }
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>
where Self: Sized,
I: LendingIterator,
F: FnMut(Self::Item<'_>, I::Item<'_>) -> Option<Ordering> { ... }
fn eq<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialEq<I::Item<'a>>,
Self: Sized { ... }
fn eq_by<I, F>(self, other: I, eq: F) -> bool
where Self: Sized,
I: LendingIterator,
F: FnMut(Self::Item<'_>, I::Item<'_>) -> bool { ... }
fn ne<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialEq<I::Item<'a>>,
Self: Sized { ... }
fn lt<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialOrd<I::Item<'a>>,
Self: Sized { ... }
fn le<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialOrd<I::Item<'a>>,
Self: Sized { ... }
fn gt<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialOrd<I::Item<'a>>,
Self: Sized { ... }
fn ge<I>(self, other: I) -> bool
where I: LendingIterator,
for<'a> Self::Item<'a>: PartialOrd<I::Item<'a>>,
Self: Sized { ... }
}
Expand description
Like Iterator
, but items may borrow from &mut self
.
This means that the compiler will check that you finish using an item
before requesting the next item, as it’s not allowed for two &mut self
to exist
at the same time.
Required Associated Types§
Required Methods§
Sourcefn next(&mut self) -> Option<Self::Item<'_>>
fn next(&mut self) -> Option<Self::Item<'_>>
Advances the lending iterator and returns the next value.
See Iterator::next
.
Provided Methods§
Sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator.
See Iterator::size_hint
.
Sourcefn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere
Self: Sized,
Returns the number of items in the lending iterator.
See Iterator::count
.
Sourcefn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
Advances the lending iterator by n
elements.
See Iterator::advance_by
.
Sourcefn nth(&mut self, n: usize) -> Option<Self::Item<'_>>
fn nth(&mut self, n: usize) -> Option<Self::Item<'_>>
Returns the n
th element of the lending iterator.
See Iterator::nth
.
Sourcefn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Creates a lending iterator starting at the same point, but stepping by the given amount at each iteration.
See Iterator::step_by
.
Sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Creates a lending iterator that lends the first n
elements, or fewer
if the underlying iterator ends sooner.
See Iterator::take
.
Sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Creates a lending iterator that lends items matching a predicate.
The predicate is called once for every item.
Once it returns false once, None
is returned for all subsequent calls to next
.
Sourcefn chain<I>(self, other: I) -> Chain<Self, I>
fn chain<I>(self, other: I) -> Chain<Self, I>
Takes two lending iterators and creates a new lending iterator over both in sequence.
See Iterator::chain
.
Sourcefn zip<I>(self, other: I) -> Zip<Self, I>where
Self: Sized,
I: LendingIterator,
fn zip<I>(self, other: I) -> Zip<Self, I>where
Self: Sized,
I: LendingIterator,
‘Zips up’ two lending iterators into a single lending iterator of pairs.
Sourcefn map<F>(self, f: F) -> Map<Self, F>
fn map<F>(self, f: F) -> Map<Self, F>
Takes a closure and creates a lending iterator which calls that closure on each element.
As of writing, in stable rust it’s not possible to create a closure
where the lifetime of its output is tied to its input.
If you’re on nightly, you can use the unstable
closure_lifetime_binder
feature. If you’re on stable, try using
a function.
In the case that the closure’s return type doesn’t borrow from its input,
the resulting LendingIterator
will implement IntoIterator
.
See Iterator::map
.
Sourcefn for_each<F>(self, f: F)
fn for_each<F>(self, f: F)
Calls a closure on each element of the lending iterator.
See Iterator::for_each
.
Sourcefn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Creates a lending iterator which uses a closure to determine if an element should be yielded.
See Iterator::filter
.
Sourcefn filter_map<F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: for<'a> SingleArgFnMut<Self::Item<'a>>,
for<'a> <F as SingleArgFnOnce<Self::Item<'a>>>::Output: OptionTrait,
fn filter_map<F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: for<'a> SingleArgFnMut<Self::Item<'a>>,
for<'a> <F as SingleArgFnOnce<Self::Item<'a>>>::Output: OptionTrait,
Creates a lending iterator that both filters and maps.
See Iterator::filter_map
.
Sourcefn fold<B, F>(self, init: B, f: F) -> B
fn fold<B, F>(self, init: B, f: F) -> B
Folds every element into an accumulator by applying an operation, returning the final result.
See Iterator::fold
.
Sourcefn cloned<T>(self) -> Cloned<Self>
fn cloned<T>(self) -> Cloned<Self>
Creates a lending iterator which clone
s all of its elements.
The resulting lending iterator implements IntoIterator
.
See Iterator::cloned
.
Sourcefn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Creates a lending iterator which gives the current iteration count as well as the next value.
Sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Creates a lending iterator that skips over the first n
elements of self.
Sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Creates a lending iterator that rejects elements while predicate
returns true
.
Sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Borrows the lending iterator.
This is useful to allow applying iterator adapters while still retaining ownership of the original iterator.
Unfortunately adapters that take in a closure are currently incompatible with this, due to limitations in the borrow checker.
Sourcefn all<P>(&mut self, predicate: P) -> bool
fn all<P>(&mut self, predicate: P) -> bool
Tests if every element of the iterator matches a predicate.
Sourcefn any<P>(&mut self, predicate: P) -> bool
fn any<P>(&mut self, predicate: P) -> bool
Tests if any element of the iterator matches a predicate.
Sourcefn is_partitioned<P>(self, predicate: P) -> bool
fn is_partitioned<P>(self, predicate: P) -> bool
Checks if the elements of this iterator are partitioned according to the given predicate,
such that all those that return true
precede all those that return false
.
Sourcefn find<P>(&mut self, predicate: P) -> Option<Self::Item<'_>>
fn find<P>(&mut self, predicate: P) -> Option<Self::Item<'_>>
Searches for an element of an iterator that satisfies a predicate.
Sourcefn find_map<B, F>(&mut self, f: F) -> Option<B>
fn find_map<B, F>(&mut self, f: F) -> Option<B>
Applies function to the elements of iterator and returns the first non-none result.
Sourcefn position<P>(&mut self, predicate: P) -> Option<usize>
fn position<P>(&mut self, predicate: P) -> Option<usize>
Searches for an element in an iterator, returning its index.
Sourcefn cmp<I>(self, other: I) -> Orderingwhere
I: for<'a> LendingIterator<Item<'a> = Self::Item<'a>>,
for<'a> Self::Item<'a>: Ord,
Self: Sized,
fn cmp<I>(self, other: I) -> Orderingwhere
I: for<'a> LendingIterator<Item<'a> = Self::Item<'a>>,
for<'a> Self::Item<'a>: Ord,
Self: Sized,
Lexicographically compares the elements of this Iterator
with those
of another.
Sourcefn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
Lexicographically compares the elements of this Iterator
with those
of another with respect to the specified comparison function.
Sourcefn partial_cmp<I>(self, other: I) -> Option<Ordering>
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
Lexicographically compares the PartialOrd
elements of
this Iterator
with those of another. The comparison works like short-circuit
evaluation, returning a result without comparing the remaining elements.
As soon as an order can be determined, the evaluation stops and a result is returned.
Sourcefn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>
Lexicographically compares the elements of this Iterator
with those
of another with respect to the specified comparison function.
Sourcefn eq<I>(self, other: I) -> bool
fn eq<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are equal to those of
another.
Sourcefn eq_by<I, F>(self, other: I, eq: F) -> bool
fn eq_by<I, F>(self, other: I, eq: F) -> bool
Determines if the elements of this Iterator
are equal to those of
another with respect to the specified equality function.
Sourcefn ne<I>(self, other: I) -> bool
fn ne<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are not equal to those of
another.
Sourcefn lt<I>(self, other: I) -> bool
fn lt<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are lexicographically
less than those of another.
Sourcefn le<I>(self, other: I) -> bool
fn le<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are lexicographically
less or equal to those of another.
Sourcefn gt<I>(self, other: I) -> bool
fn gt<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are lexicographically
greater than those of another.
Sourcefn ge<I>(self, other: I) -> bool
fn ge<I>(self, other: I) -> bool
Determines if the elements of this Iterator
are lexicographically
greater or equal to those of another.
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.