pub trait FallibleLender: for<'all> FallibleLending<'all> {
type Error;
Show 81 methods
// Required methods
fn __check_covariance<'long: 'short, 'short>(
proof: CovariantProof<&'short <Self as FallibleLending<'long>>::Lend>,
) -> CovariantProof<&'short <Self as FallibleLending<'short>>::Lend>;
fn next(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>;
// Provided methods
fn next_chunk(&mut self, chunk_size: usize) -> Chunk<'_, Self>
where Self: Sized { ... }
fn size_hint(&self) -> (usize, Option<usize>) { ... }
fn count(self) -> Result<usize, Self::Error>
where Self: Sized { ... }
fn last<'call>(
&'call mut self,
) -> Result<Option<FallibleLend<'call, Self>>, Self::Error>
where Self: Sized { ... }
fn advance_by(
&mut self,
n: usize,
) -> Result<Result<(), NonZeroUsize>, Self::Error> { ... }
fn nth(
&mut self,
n: usize,
) -> Result<Option<FallibleLend<'_, Self>>, Self::Error> { ... }
fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized { ... }
fn chain<U>(
self,
other: U,
) -> Chain<Self, <U as IntoFallibleLender>::FallibleLender>
where Self: Sized,
U: IntoFallibleLender<Error = Self::Error> + for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>> { ... }
fn zip<U: IntoFallibleLender>(
self,
other: U,
) -> Zip<Self, <U as IntoFallibleLender>::FallibleLender>
where Self: Sized { ... }
fn intersperse<'call>(
self,
separator: FallibleLend<'call, Self>,
) -> FallibleIntersperse<'call, Self>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: Clone { ... }
fn intersperse_with<'call, G>(
self,
separator: G,
) -> FallibleIntersperseWith<'call, Self, G>
where Self: Sized,
G: FnMut() -> Result<FallibleLend<'call, Self>, Self::Error> { ... }
fn map<F>(self, f: Covar<F>) -> Map<Self, F>
where Self: Sized,
F: for<'all> FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error> { ... }
fn map_err<E, F>(self, f: F) -> MapErr<E, Self, F>
where Self: Sized,
F: FnMut(Self::Error) -> E { ... }
fn map_into_iter<O, F>(self, f: F) -> MapIntoIter<Self, O, F> ⓘ
where Self: Sized,
F: FnMut(FallibleLend<'_, Self>) -> Result<O, Self::Error> { ... }
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
where Self: Sized,
F: FnMut(FallibleLend<'_, Self>) -> Result<(), Self::Error> { ... }
fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized,
P: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn filter_map<F>(self, f: Covar<F>) -> FilterMap<Self, F>
where Self: Sized,
F: for<'all> FnMutHKAResOpt<'all, FallibleLend<'all, Self>, Self::Error> { ... }
fn enumerate(self) -> Enumerate<Self>
where Self: Sized { ... }
fn peekable<'call>(self) -> FalliblePeekable<'call, Self>
where Self: Sized { ... }
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized,
P: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized,
P: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn map_while<P>(self, predicate: Covar<P>) -> MapWhile<Self, P>
where Self: Sized,
P: for<'all> FnMutHKAResOpt<'all, FallibleLend<'all, Self>, Self::Error> { ... }
fn skip(self, n: usize) -> Skip<Self>
where Self: Sized { ... }
fn take(self, n: usize) -> Take<Self>
where Self: Sized { ... }
fn scan<St, F>(self, initial_state: St, f: Covar<F>) -> Scan<Self, St, F>
where Self: Sized,
F: for<'all> FnMutHKAResOpt<'all, (&'all mut St, FallibleLend<'all, Self>), Self::Error> { ... }
fn flat_map<'call, F>(self, f: Covar<F>) -> FallibleFlatMap<'call, Self, F>
where Self: Sized,
F: for<'all> FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>,
for<'all> <F as FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>>::B: IntoFallibleLender<Error = Self::Error> { ... }
fn flatten<'call>(self) -> FallibleFlatten<'call, Self>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: IntoFallibleLender<Error = Self::Error> { ... }
fn fuse(self) -> Fuse<Self>
where Self: Sized { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized,
F: FnMut(&FallibleLend<'_, Self>) -> Result<(), Self::Error> { ... }
fn mutate<F>(self, f: F) -> Mutate<Self, F>
where Self: Sized,
F: FnMut(&mut FallibleLend<'_, Self>) -> Result<(), Self::Error> { ... }
fn by_ref(&mut self) -> &mut Self
where Self: Sized { ... }
fn collect<B>(self) -> Result<B, (B, Self::Error)>
where Self: Sized,
for<'all> B: FromLender<NonFallibleAdapter<'all, Self>> { ... }
fn try_collect<'a, B, T>(&'a mut self) -> Result<T, (T, Self::Error)>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: Try,
for<'all> <FallibleLend<'all, Self> as Try>::Residual: Residual<B, TryType = T>,
for<'b, 'c, 'd> B: FromLender<FallibleTryShuntAdapter<'b, 'c, 'd, 'a, Self>> { ... }
fn collect_into<E>(
self,
collection: &mut E,
) -> Result<&mut E, (&mut E, Self::Error)>
where Self: Sized,
for<'all> E: ExtendLender<NonFallibleAdapter<'all, Self>> { ... }
fn partition<'this, E, F>(
self,
f: F,
) -> Result<(E, E), ((E, E), Self::Error)>
where Self: Sized + 'this,
E: Default + ExtendLender<NonFallibleAdapter<'this, Self>>,
F: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn is_partitioned<P>(self, predicate: P) -> Result<bool, Self::Error>
where Self: Sized,
P: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Result<R, Self::Error>
where F: FnMut(B, FallibleLend<'_, Self>) -> Result<R, Self::Error>,
R: Try<Output = B> { ... }
fn try_for_each<F, R>(&mut self, f: F) -> Result<R, Self::Error>
where F: FnMut(FallibleLend<'_, Self>) -> Result<R, Self::Error>,
R: Try<Output = ()> { ... }
fn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
where Self: Sized,
F: FnMut(B, FallibleLend<'_, Self>) -> Result<B, Self::Error> { ... }
fn reduce<T, F>(self, f: F) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(T, FallibleLend<'_, Self>) -> Result<T, Self::Error> { ... }
fn try_reduce<T, F, R>(
self,
f: F,
) -> Result<ChangeOutputType<R, Option<T>>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(T, FallibleLend<'_, Self>) -> Result<R, Self::Error>,
R: Try<Output = T>,
R::Residual: Residual<Option<T>> { ... }
fn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
where F: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
where F: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn find<P>(
&mut self,
predicate: P,
) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
where P: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn find_map<'a, F>(
&'a mut self,
f: F,
) -> Result<Option<<F as FnMutHKAResOpt<'a, FallibleLend<'a, Self>, Self::Error>>::B>, Self::Error>
where Self: Sized,
F: for<'all> FnMutHKAResOpt<'all, FallibleLend<'all, Self>, Self::Error> { ... }
fn try_find<F, R>(
&mut self,
f: F,
) -> Result<ChangeOutputType<R, Option<FallibleLend<'_, Self>>>, Self::Error>
where Self: Sized,
F: FnMut(&FallibleLend<'_, Self>) -> Result<R, Self::Error>,
R: Try<Output = bool>,
for<'all> R::Residual: Residual<Option<FallibleLend<'all, Self>>> { ... }
fn position<P>(
&mut self,
predicate: P,
) -> Result<Option<usize>, Self::Error>
where Self: Sized,
P: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error> { ... }
fn rposition<P>(
&mut self,
predicate: P,
) -> Result<Option<usize>, Self::Error>
where P: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error>,
Self: Sized + ExactSizeFallibleLender + DoubleEndedFallibleLender { ... }
fn max<T: Ord>(self) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T> { ... }
fn min<T: Ord>(self) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T> { ... }
fn max_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T) -> Result<B, Self::Error> { ... }
fn max_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error> { ... }
fn min_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T) -> Result<B, Self::Error> { ... }
fn min_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error> { ... }
fn rev(self) -> Rev<Self>
where Self: Sized + DoubleEndedFallibleLender { ... }
fn unzip<ExtA, ExtB>(self) -> Result<(ExtA, ExtB), Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: TupleLend<'all>,
ExtA: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <FirstShunt<Self> as IntoFallibleLender>::FallibleLender>>,
ExtB: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <SecondShunt<Self> as IntoFallibleLender>::FallibleLender>> { ... }
fn copied<T>(self) -> Copied<Self> ⓘ
where Self: Sized + for<'all> FallibleLending<'all, Lend = &'all T>,
T: Copy { ... }
fn cloned<T>(self) -> Cloned<Self> ⓘ
where Self: Sized + for<'all> FallibleLending<'all, Lend = &'all T>,
T: Clone { ... }
fn owned(self) -> Owned<Self> ⓘ
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned { ... }
fn cycle(self) -> Cycle<Self>
where Self: Sized + Clone { ... }
fn sum<S>(self) -> Result<S, Self::Error>
where Self: Sized,
S: SumFallibleLender<Self> { ... }
fn product<P>(self) -> Result<P, Self::Error>
where Self: Sized,
P: ProductFallibleLender<Self> { ... }
fn cmp<L>(self, other: L) -> Result<Ordering, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
L::FallibleLender: for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>>,
for<'all> FallibleLend<'all, Self>: Ord,
Self: Sized { ... }
fn cmp_by<L, F>(self, other: L, cmp: F) -> Result<Ordering, Self::Error>
where Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Ordering, Self::Error> { ... }
fn partial_cmp<L>(self, other: L) -> Result<Option<Ordering>, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn partial_cmp_by<L, F>(
self,
other: L,
partial_cmp: F,
) -> Result<Option<Ordering>, Self::Error>
where Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Option<Ordering>, Self::Error> { ... }
fn eq<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn eq_by<L, F>(self, other: L, eq: F) -> Result<bool, Self::Error>
where Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<bool, Self::Error> { ... }
fn ne<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn lt<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn le<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn gt<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn ge<L>(self, other: L) -> Result<bool, Self::Error>
where L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized { ... }
fn is_sorted<T>(self) -> Result<bool, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
T: PartialOrd { ... }
fn is_sorted_by<T, F>(self, compare: F) -> Result<bool, Self::Error>
where Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &T) -> Result<Option<Ordering>, Self::Error> { ... }
fn is_sorted_by_key<F, K>(self, f: F) -> Result<bool, Self::Error>
where Self: Sized,
F: FnMut(FallibleLend<'_, Self>) -> Result<K, Self::Error>,
K: PartialOrd { ... }
fn chunky(self, chunk_size: usize) -> Chunky<Self>
where Self: Sized + ExactSizeFallibleLender { ... }
fn iter<'this>(self) -> Iter<'this, Self> ⓘ
where Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this { ... }
fn lender_by_ref<'this>(self) -> FromFallibleIterRef<Iter<'this, Self>>
where Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this { ... }
}Expand description
A trait for dealing with fallible lending iterators.
This is the main fallible lender trait. For more about the concept of lenders generally, please see the crate documentation.
For more about the concept of iterators
generally, please see core::iter.
§Covariance Checking
This crate provide a mechanism to guarantee that the
Lend type of a fallible lender is covariant in
its lifetime. This is crucial to avoid undefined behavior, as many of the
operations on lenders rely on covariance to ensure that lends do not outlive
their lenders.
The mechanism is based on the
__check_covariance method of this
trait, which is an internal method for compile-time covariance checking.
Adapters relying on covariance of other fallible lenders should call this
method for the lenders they are adapting.
The mechanism can be circumvented with unsafe code, and in this case the
burden of checking covariance is on the implementor. However, there’s no way
to prevent that __check_covariance
is implemented vacuously using a non-returning statement (todo!(),
unimplemented!(), panic!(), loop {}, etc.), unless you call the method
explicitly somewhere in your code. Adapters will call recursively adapted
lenders, but there is no way to force the call on the user-facing type.
Required Associated Types§
Required Methods§
Sourcefn __check_covariance<'long: 'short, 'short>(
proof: CovariantProof<&'short <Self as FallibleLending<'long>>::Lend>,
) -> CovariantProof<&'short <Self as FallibleLending<'short>>::Lend>
fn __check_covariance<'long: 'short, 'short>( proof: CovariantProof<&'short <Self as FallibleLending<'long>>::Lend>, ) -> CovariantProof<&'short <Self as FallibleLending<'short>>::Lend>
Internal method for compile-time covariance checking.
This method should rarely be implemented directly. Instead, use the provided macros:
-
When implementing source lenders (lenders with concrete
Lendtypes), users should invokecheck_covariance_fallible!in theirFallibleLenderimpl. The macro implements the method as{ proof }, which only compiles if theLendtype is covariant in its lifetime. -
In all other cases (e.g., when implementing adapters), use
unsafe_assume_covariance_fallible!in theFallibleLenderimpl. The macro implements the method as{ unsafe { core::mem::transmute(proof) } }, which is a no-op. This is unsafe because it is up to the implementor to guarantee that theLendtype is covariant in its lifetime.
When relying on covariance of other types, this method should
be called in every constructor, or in every method requiring
covariance, of such types. In particular, adapters should call
this method for the lender they are adapting. The call makes it
impossible to implement the check with non-returning code
(todo!(), unimplemented!(), panic!(), loop {}, etc.).
See crate::Lender::__check_covariance for more details
on how this method works.
Sourcefn next(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
fn next(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
Yields the next lend, if any, of the lender, or Ok(None) when iteration
is finished.
The behavior of calling this method after a previous call has returned
Ok(None) or Err is implementation defined. See
FusedFallibleLender for lenders that
guarantee Ok(None) is repeated after Ok(None).
Every lend is only guaranteed to be valid one at a time for any kind of lender.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.next(), Ok(Some(&1)));
assert_eq!(lender.next(), Ok(Some(&2)));
assert_eq!(lender.next(), Ok(Some(&3)));
assert_eq!(lender.next(), Ok(None));Provided Methods§
Sourcefn next_chunk(&mut self, chunk_size: usize) -> Chunk<'_, Self>where
Self: Sized,
fn next_chunk(&mut self, chunk_size: usize) -> Chunk<'_, Self>where
Self: Sized,
Takes the next chunk_size lends of the lender with temporary lender
Chunk. This is equivalent to cloning the lender and calling
take(chunk_size) on it.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut chunk_lender = lender.next_chunk(2);
assert_eq!(chunk_lender.next(), Ok(Some(&1)));
assert_eq!(chunk_lender.next(), Ok(Some(&2)));
assert_eq!(chunk_lender.next(), Ok(None));Sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Gets the estimated minimum and maximum length of the lender. Both
bounds assume that all remaining calls to
next() succeed. That is,
next() could return an Err in fewer
calls than specified by the lower bound.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.size_hint(), (3, Some(3)));Sourcefn count(self) -> Result<usize, Self::Error>where
Self: Sized,
fn count(self) -> Result<usize, Self::Error>where
Self: Sized,
Counts the number of lends in the lender by consuming it until the
lender yields Ok(None) or Err(_).
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.count(), Ok(3));Sourcefn last<'call>(
&'call mut self,
) -> Result<Option<FallibleLend<'call, Self>>, Self::Error>where
Self: Sized,
fn last<'call>(
&'call mut self,
) -> Result<Option<FallibleLend<'call, Self>>, Self::Error>where
Self: Sized,
Gets the last lend of the lender, if any, by consuming it.
Unlike Iterator::last, this method takes &mut self
rather than self because returning a lend that borrows
from the lender requires the lender to remain alive.
§Examples
let mut lender =
lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.last(), Ok(Some(&3)));Sourcefn advance_by(
&mut self,
n: usize,
) -> Result<Result<(), NonZeroUsize>, Self::Error>
fn advance_by( &mut self, n: usize, ) -> Result<Result<(), NonZeroUsize>, Self::Error>
Advances the lender by n lends.
Returns Ok(Ok(())) if the lender was successfully advanced by n elements.
Returns Ok(Err(k)) if the lender did not have enough elements, where k is
the number of elements that could not be skipped.
Returns Err(e) if an error occurred while advancing.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.advance_by(2), Ok(Ok(())));
assert_eq!(lender.next(), Ok(Some(&3)));let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
// Trying to advance by 5 when only 2 elements remain
assert_eq!(lender.advance_by(5), Ok(Err(NonZeroUsize::new(3).unwrap())));Sourcefn nth(
&mut self,
n: usize,
) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
fn nth( &mut self, n: usize, ) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
Yields the nth lend of the lender, if any, by
consuming it. If the lender does not have enough
lends, returns Ok(None).
n is zero-indexed.
§Examples
let data = [1, 2, 3, 4, 5];
let mut lender =
data.iter().into_lender().into_fallible();
assert_eq!(lender.nth(2), Ok(Some(&3)));
assert_eq!(lender.nth(0), Ok(Some(&4)));
assert_eq!(lender.nth(5), Ok(None));Sourcefn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Skips step - 1 lends between each lend of the lender.
§Panics
Panics if step is zero.
§Examples
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].iter().into_fallible(),
);
let mut step_lender = lender.step_by(2);
assert_eq!(step_lender.next(), Ok(Some(&1)));
assert_eq!(step_lender.next(), Ok(Some(&3)));
assert_eq!(step_lender.next(), Ok(Some(&5)));
assert_eq!(step_lender.next(), Ok(Some(&7)));
assert_eq!(step_lender.next(), Ok(Some(&9)));
assert_eq!(step_lender.next(), Ok(None));Sourcefn chain<U>(
self,
other: U,
) -> Chain<Self, <U as IntoFallibleLender>::FallibleLender>where
Self: Sized,
U: IntoFallibleLender<Error = Self::Error> + for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>>,
fn chain<U>(
self,
other: U,
) -> Chain<Self, <U as IntoFallibleLender>::FallibleLender>where
Self: Sized,
U: IntoFallibleLender<Error = Self::Error> + for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>>,
Chains the lender with another lender of the same type.
The resulting lender will first yield all lends from self, then
all lends from other.
§Examples
let a = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let b = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[3, 4].iter().into_fallible(),
);
let mut chained = a.chain(b);
assert_eq!(chained.next(), Ok(Some(&1)));
assert_eq!(chained.next(), Ok(Some(&2)));
assert_eq!(chained.next(), Ok(Some(&3)));
assert_eq!(chained.next(), Ok(Some(&4)));
assert_eq!(chained.next(), Ok(None));Sourcefn zip<U: IntoFallibleLender>(
self,
other: U,
) -> Zip<Self, <U as IntoFallibleLender>::FallibleLender>where
Self: Sized,
fn zip<U: IntoFallibleLender>(
self,
other: U,
) -> Zip<Self, <U as IntoFallibleLender>::FallibleLender>where
Self: Sized,
Zips the lender with another lender of the same or different type.
§Examples
let a = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let b = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[3, 4].iter().into_fallible(),
);
let mut zipped = a.zip(b);
assert_eq!(zipped.next(), Ok(Some((&1, &3))));
assert_eq!(zipped.next(), Ok(Some((&2, &4))));
assert_eq!(zipped.next(), Ok(None));Sourcefn intersperse<'call>(
self,
separator: FallibleLend<'call, Self>,
) -> FallibleIntersperse<'call, Self>
fn intersperse<'call>( self, separator: FallibleLend<'call, Self>, ) -> FallibleIntersperse<'call, Self>
Intersperses each lend of this lender with the given separator.
§Examples
let sep = 0;
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut inter = lender.intersperse(&sep);
assert_eq!(inter.next(), Ok(Some(&1)));
assert_eq!(inter.next(), Ok(Some(&0)));
assert_eq!(inter.next(), Ok(Some(&2)));
assert_eq!(inter.next(), Ok(Some(&0)));
assert_eq!(inter.next(), Ok(Some(&3)));
assert_eq!(inter.next(), Ok(None));Sourcefn intersperse_with<'call, G>(
self,
separator: G,
) -> FallibleIntersperseWith<'call, Self, G>
fn intersperse_with<'call, G>( self, separator: G, ) -> FallibleIntersperseWith<'call, Self, G>
Intersperses each lend of this lender with the separator produced by the given function.
§Examples
let sep = 0;
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut inter = lender.intersperse_with(|| Ok(&sep));
assert_eq!(inter.next(), Ok(Some(&1)));
assert_eq!(inter.next(), Ok(Some(&0)));
assert_eq!(inter.next(), Ok(Some(&2)));
assert_eq!(inter.next(), Ok(Some(&0)));
assert_eq!(inter.next(), Ok(Some(&3)));
assert_eq!(inter.next(), Ok(None));Sourcefn map<F>(self, f: Covar<F>) -> Map<Self, F>
fn map<F>(self, f: Covar<F>) -> Map<Self, F>
Maps each lend of this lender using the given function.
Note that functions passed to this method must be built using the
covar! or covar_mut! macros, which also
checks for covariance of the returned type.
§Examples
let mut data = [1, 2];
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend mut i32), _>(
data.iter_mut().into_fallible(),
);
let mut mapped = lender.map(covar_mut!(
for<'all> |a: &'all mut i32| -> Result<&'all i32, Infallible> {
*a += 1;
Ok(&*a)
}
));
assert_eq!(mapped.next().unwrap(), Some(&2));Sourcefn map_err<E, F>(self, f: F) -> MapErr<E, Self, F>
fn map_err<E, F>(self, f: F) -> MapErr<E, Self, F>
Maps the error of this lender using the given function.
§Examples
let data = [Ok(1), Ok(2), Err("oops")];
let mut lender = data.into_iter().into_lender()
.convert::<&str>()
.map_err(|e| format!("error: {e}"));
assert_eq!(lender.next(), Ok(Some(1)));
assert_eq!(lender.next(), Ok(Some(2)));
assert_eq!(lender.next(), Err(String::from("error: oops")));Sourcefn map_into_iter<O, F>(self, f: F) -> MapIntoIter<Self, O, F> ⓘ
fn map_into_iter<O, F>(self, f: F) -> MapIntoIter<Self, O, F> ⓘ
Maps each lend of this lender into an owned value using the given function.
This is a weaker version of FallibleLender::map that returns a
FallibleIterator instead
of a FallibleLender. However, this behavior is very common, and so
this method is included for convenience. The main advantage is better
type inference for the mapping function.
§Examples
let mut data = [1, 2];
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend mut i32), _>(
data.iter_mut().into_fallible(),
);
let mut mapped_into_iter = lender.map_into_iter(|a| { Ok(*a + 10) });
assert_eq!(mapped_into_iter.next(), Ok(Some(11)));
assert_eq!(mapped_into_iter.next(), Ok(Some(12)));
assert_eq!(mapped_into_iter.next(), Ok(None));Sourcefn for_each<F>(self, f: F) -> Result<(), Self::Error>
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
Calls the given function with each lend of this lender.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut sum = 0;
lender.for_each(|&x| { sum += x; Ok(()) }).unwrap();
assert_eq!(sum, 6);Sourcefn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Filters this lender using the given predicate.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut filtered = lender.filter(|&&x| Ok(x > 1));
assert_eq!(filtered.next(), Ok(Some(&2)));
assert_eq!(filtered.next(), Ok(Some(&3)));
assert_eq!(filtered.next(), Ok(None));Sourcefn filter_map<F>(self, f: Covar<F>) -> FilterMap<Self, F>
fn filter_map<F>(self, f: Covar<F>) -> FilterMap<Self, F>
Filters and maps this lender using the given function.
Note that functions passed to this method must be built using the
covar! or covar_mut! macros, which also
checks for covariance of the returned type.
§Examples
let mut data = [1, 2];
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend mut i32), _>(
data.iter_mut().into_fallible(),
);
let mut filtered = lender.filter_map(covar_mut!(
for<'all> |a: &'all mut i32| -> Result<Option<&'all i32>, Infallible> {
if *a > 1 { Ok(Some(&*a)) } else { Ok(None) }
}
));
assert_eq!(filtered.next().unwrap(), Some(&2));Sourcefn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Enumerates this lender. Each lend is paired with its zero-based index.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut enumerated = lender.enumerate();
assert_eq!(enumerated.next(), Ok(Some((0, &1))));
assert_eq!(enumerated.next(), Ok(Some((1, &2))));
assert_eq!(enumerated.next(), Ok(Some((2, &3))));
assert_eq!(enumerated.next(), Ok(None));Sourcefn peekable<'call>(self) -> FalliblePeekable<'call, Self>where
Self: Sized,
fn peekable<'call>(self) -> FalliblePeekable<'call, Self>where
Self: Sized,
Makes this lender peekable, so that it is possible to peek at the next lend without consuming it.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let mut peekable = lender.peekable();
assert_eq!(peekable.peek(), Ok(Some(&&1)));
assert_eq!(peekable.next(), Ok(Some(&1)));
assert_eq!(peekable.peek(), Ok(Some(&&2)));
assert_eq!(peekable.next(), Ok(Some(&2)));
assert_eq!(peekable.peek(), Ok(None));Sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Skips the first contiguous sequence of lends of this lender that satisfy the given predicate.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut skipped = lender.skip_while(|&&x| Ok(x < 3));
assert_eq!(skipped.next(), Ok(Some(&3)));
assert_eq!(skipped.next(), Ok(None));Sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Takes the first contiguous sequence of lends of this lender that satisfy the given predicate.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut taken = lender.take_while(|&&x| Ok(x < 3));
assert_eq!(taken.next(), Ok(Some(&1)));
assert_eq!(taken.next(), Ok(Some(&2)));
assert_eq!(taken.next(), Ok(None));Sourcefn map_while<P>(self, predicate: Covar<P>) -> MapWhile<Self, P>
fn map_while<P>(self, predicate: Covar<P>) -> MapWhile<Self, P>
Maps this lender using the given function while it returns Some.
Note that functions passed to this method must be built using the
covar! or covar_mut! macros, which also
checks for covariance of the returned type.
§Examples
let mut data = [1, 2];
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend mut i32), _>(
data.iter_mut().into_fallible(),
);
let mut mapped = lender.map_while(covar_mut!(
for<'all> |a: &'all mut i32| -> Result<Option<&'all i32>, Infallible> {
if *a < 2 { Ok(Some(&*a)) } else { Ok(None) }
}
));
assert_eq!(mapped.next().unwrap(), Some(&1));
assert_eq!(mapped.next().unwrap(), None);Sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Skips the first n lends of this lender.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut skipped = lender.skip(2);
assert_eq!(skipped.next(), Ok(Some(&3)));
assert_eq!(skipped.next(), Ok(None));Sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Takes the first n lends of this lender.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut taken = lender.take(2);
assert_eq!(taken.next(), Ok(Some(&1)));
assert_eq!(taken.next(), Ok(Some(&2)));
assert_eq!(taken.next(), Ok(None));Sourcefn scan<St, F>(self, initial_state: St, f: Covar<F>) -> Scan<Self, St, F>where
Self: Sized,
F: for<'all> FnMutHKAResOpt<'all, (&'all mut St, FallibleLend<'all, Self>), Self::Error>,
fn scan<St, F>(self, initial_state: St, f: Covar<F>) -> Scan<Self, St, F>where
Self: Sized,
F: for<'all> FnMutHKAResOpt<'all, (&'all mut St, FallibleLend<'all, Self>), Self::Error>,
The FallibleLender version of Iterator::scan.
Note that functions passed to this method must be built using the
covar! or covar_mut! macros, which also
checks for covariance of the returned type.
§Examples
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut scanned = lender.scan(
0,
covar_mut!(
for<'all> |args: (&'all mut i32, &'all i32)|
-> Result<Option<&'all i32>, Infallible>
{
*args.0 += *args.1;
Ok(Some(args.1))
}
),
);
assert_eq!(scanned.next().unwrap(), Some(&1));
assert_eq!(scanned.next().unwrap(), Some(&2));Sourcefn flat_map<'call, F>(self, f: Covar<F>) -> FallibleFlatMap<'call, Self, F>where
Self: Sized,
F: for<'all> FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>,
for<'all> <F as FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>>::B: IntoFallibleLender<Error = Self::Error>,
fn flat_map<'call, F>(self, f: Covar<F>) -> FallibleFlatMap<'call, Self, F>where
Self: Sized,
F: for<'all> FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>,
for<'all> <F as FnMutHKARes<'all, FallibleLend<'all, Self>, Self::Error>>::B: IntoFallibleLender<Error = Self::Error>,
The FallibleLender version of Iterator::flat_map.
Note that functions passed to this method must be built using the
covar! or covar_mut! macros, which also
checks for covariance of the returned type.
§Examples
// Define a wrapper that implements FallibleLender
struct VecLender(Vec<i32>);
impl<'lend> FallibleLending<'lend> for VecLender {
type Lend = i32;
}
impl FallibleLender for VecLender {
type Error = Infallible;
check_covariance_fallible!();
fn next(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error> {
Ok(if self.0.is_empty() { None } else { Some(self.0.remove(0)) })
}
}
let data = [1, 2, 3];
let mut flat = data.into_iter().into_lender().into_fallible().flat_map(
covar_mut!(for<'lend> |x: i32| -> Result<VecLender, Infallible> {
Ok(VecLender(vec![x, x * 10]))
})
);
assert_eq!(flat.next().unwrap(), Some(1));
assert_eq!(flat.next().unwrap(), Some(10));
assert_eq!(flat.next().unwrap(), Some(2));Sourcefn flatten<'call>(self) -> FallibleFlatten<'call, Self>
fn flatten<'call>(self) -> FallibleFlatten<'call, Self>
The FallibleLender version of Iterator::flatten.
§Examples
let data = [vec![1, 2], vec![3, 4]];
let lender = data.into_iter().into_lender()
.into_fallible();
let mut flat = lender.map(covar!(
for<'all> |v: Vec<i32>|
-> Result<lender::IntoFallible<lender::FromIter<
std::vec::IntoIter<i32>
>>, Infallible>
{
Ok(v.into_iter().into_lender().into_fallible())
}
)).flatten();
assert_eq!(flat.next().unwrap(), Some(1));
assert_eq!(flat.next().unwrap(), Some(2));
assert_eq!(flat.next().unwrap(), Some(3));
assert_eq!(flat.next().unwrap(), Some(4));
assert_eq!(flat.next().unwrap(), None);Sourcefn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
The FallibleLender version of Iterator::fuse.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let mut fused = lender.fuse();
assert_eq!(fused.next(), Ok(Some(&1)));
assert_eq!(fused.next(), Ok(Some(&2)));
assert_eq!(fused.next(), Ok(None));
assert_eq!(fused.next(), Ok(None));Sourcefn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
The FallibleLender version of Iterator::inspect.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut sum = 0;
let mut inspected = lender.inspect(|&x| { sum += x; Ok(()) });
assert_eq!(inspected.next(), Ok(Some(&1)));
assert_eq!(inspected.next(), Ok(Some(&2)));
assert_eq!(inspected.next(), Ok(Some(&3)));
assert_eq!(inspected.next(), Ok(None));
assert_eq!(sum, 6);Sourcefn mutate<F>(self, f: F) -> Mutate<Self, F>
fn mutate<F>(self, f: F) -> Mutate<Self, F>
Mutates each lend with the given function.
§Examples
let mut data = [1, 2, 3];
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend mut i32), _>(
data.iter_mut().into_fallible(),
);
let mut mutated = lender.mutate(|x| { **x += 10; Ok(()) });
assert_eq!(mutated.next(), Ok(Some(&mut 11)));
assert_eq!(mutated.next(), Ok(Some(&mut 12)));
assert_eq!(mutated.next(), Ok(Some(&mut 13)));
assert_eq!(mutated.next(), Ok(None));Sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
The FallibleLender version of
Iterator::by_ref.
§Examples
let data = [1, 2, 3, 4, 5];
let mut lender =
data.iter().into_lender().into_fallible();
// Consume two elements through by_ref.
assert_eq!(
lender.by_ref().next(),
Ok(Some(&1))
);
assert_eq!(
lender.by_ref().next(),
Ok(Some(&2))
);
// The original lender continues from where
// we left off.
assert_eq!(lender.next(), Ok(Some(&3)));Sourcefn collect<B>(self) -> Result<B, (B, Self::Error)>where
Self: Sized,
for<'all> B: FromLender<NonFallibleAdapter<'all, Self>>,
fn collect<B>(self) -> Result<B, (B, Self::Error)>where
Self: Sized,
for<'all> B: FromLender<NonFallibleAdapter<'all, Self>>,
Transforms the fallible lender into a collection. If any invocation of next returns Err, returns the collection built from values yielded successfully, together with the error.
§Error Handling
The return type Result<B, (B, Self::Error)> preserves partial
results even on error: the B inside the Err variant contains
whatever was accumulated before the error occurred.
§Examples
let lender = [1, 2, 3].into_iter().into_lender().into_fallible();
let collected: Result<Vec<i32>, _> = lender.owned().collect();
assert_eq!(collected, Ok(vec![1, 2, 3]));Sourcefn try_collect<'a, B, T>(&'a mut self) -> Result<T, (T, Self::Error)>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: Try,
for<'all> <FallibleLend<'all, Self> as Try>::Residual: Residual<B, TryType = T>,
for<'b, 'c, 'd> B: FromLender<FallibleTryShuntAdapter<'b, 'c, 'd, 'a, Self>>,
fn try_collect<'a, B, T>(&'a mut self) -> Result<T, (T, Self::Error)>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: Try,
for<'all> <FallibleLend<'all, Self> as Try>::Residual: Residual<B, TryType = T>,
for<'b, 'c, 'd> B: FromLender<FallibleTryShuntAdapter<'b, 'c, 'd, 'a, Self>>,
Collects the lends of a fallible lender that are themselves Try types
into a collection of their outputs, short-circuiting on both lender errors
and Try failures.
The FallibleLender version of
Lender::try_collect.
On error, returns the collection (with partial results) together with the error.
Sourcefn collect_into<E>(
self,
collection: &mut E,
) -> Result<&mut E, (&mut E, Self::Error)>where
Self: Sized,
for<'all> E: ExtendLender<NonFallibleAdapter<'all, Self>>,
fn collect_into<E>(
self,
collection: &mut E,
) -> Result<&mut E, (&mut E, Self::Error)>where
Self: Sized,
for<'all> E: ExtendLender<NonFallibleAdapter<'all, Self>>,
Extends an existing collection with lends from this fallible lender.
The FallibleLender version of
Lender::collect_into.
On error, returns the collection (with partial results) together with
the error.
Sourcefn partition<'this, E, F>(self, f: F) -> Result<(E, E), ((E, E), Self::Error)>where
Self: Sized + 'this,
E: Default + ExtendLender<NonFallibleAdapter<'this, Self>>,
F: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error>,
fn partition<'this, E, F>(self, f: F) -> Result<(E, E), ((E, E), Self::Error)>where
Self: Sized + 'this,
E: Default + ExtendLender<NonFallibleAdapter<'this, Self>>,
F: FnMut(&FallibleLend<'_, Self>) -> Result<bool, Self::Error>,
The FallibleLender version of Iterator::partition.
On error, returns the partial results accumulated so far together
with the error, matching the convention used by
collect.
Sourcefn is_partitioned<P>(self, predicate: P) -> Result<bool, Self::Error>
fn is_partitioned<P>(self, predicate: P) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::is_partitioned.
§Examples
// [1, 3, 2, 4] is partitioned: all odd elements come before all even.
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 3, 2, 4].iter().into_fallible(),
);
assert!(lender.is_partitioned(|&x| Ok(x % 2 != 0)).unwrap());Sourcefn try_fold<B, F, R>(&mut self, init: B, f: F) -> Result<R, Self::Error>
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Result<R, Self::Error>
The FallibleLender version of Iterator::try_fold.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let sum = lender.try_fold(0, |acc: i32, &x| Ok(acc.checked_add(x)));
assert_eq!(sum, Ok(Some(6)));Sourcefn try_for_each<F, R>(&mut self, f: F) -> Result<R, Self::Error>
fn try_for_each<F, R>(&mut self, f: F) -> Result<R, Self::Error>
The FallibleLender version of Iterator::try_for_each.
§Examples
let mut lender =
lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let result = lender.try_for_each(|&x| {
if x < 3 { Ok(Some(())) } else { Ok(None) }
});
assert_eq!(result, Ok(None));Sourcefn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
fn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
The FallibleLender version of Iterator::fold.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let sum = lender.fold(0, |acc, &x| Ok(acc + x));
assert_eq!(sum, Ok(6));// Example concatenating strings
let data = ["hello", " ", "world"];
let lender = lender::lend_fallible_iter::<fallible_lend!(&&'lend str), _>(
data.iter().into_fallible(),
);
let result = lender.fold(String::new(), |mut acc, &s| {
acc.push_str(s);
Ok(acc)
});
assert_eq!(result, Ok(String::from("hello world")));Sourcefn reduce<T, F>(self, f: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(T, FallibleLend<'_, Self>) -> Result<T, Self::Error>,
fn reduce<T, F>(self, f: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(T, FallibleLend<'_, Self>) -> Result<T, Self::Error>,
The FallibleLender version of Iterator::reduce.
§Error Handling
If the closure or the underlying lender returns an error, reduce
propagates it immediately. Unlike collect,
the partial accumulation is not preserved on error.
Sourcefn try_reduce<T, F, R>(
self,
f: F,
) -> Result<ChangeOutputType<R, Option<T>>, Self::Error>
fn try_reduce<T, F, R>( self, f: F, ) -> Result<ChangeOutputType<R, Option<T>>, Self::Error>
The FallibleLender version of Iterator::try_reduce.
§Examples
let lender =
[1, 2, 3].into_iter().into_lender().into_fallible();
let sum = lender.try_reduce(|acc: i32, x| {
Ok(acc.checked_add(x))
});
assert_eq!(sum, Ok(Some(Some(6))));Sourcefn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
fn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::all.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.all(|&x| Ok(x > 0)), Ok(true));let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.all(|&x| Ok(x > 2)), Ok(false));Sourcefn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
fn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::any.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.any(|&x| Ok(x == 2)), Ok(true));let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.any(|&x| Ok(x > 5)), Ok(false));Sourcefn find<P>(
&mut self,
predicate: P,
) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
fn find<P>( &mut self, predicate: P, ) -> Result<Option<FallibleLend<'_, Self>>, Self::Error>
The FallibleLender version of Iterator::find.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.find(|&&x| Ok(x == 2)), Ok(Some(&2)));let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.find(|&&x| Ok(x > 10)), Ok(None));Sourcefn find_map<'a, F>(
&'a mut self,
f: F,
) -> Result<Option<<F as FnMutHKAResOpt<'a, FallibleLend<'a, Self>, Self::Error>>::B>, Self::Error>
fn find_map<'a, F>( &'a mut self, f: F, ) -> Result<Option<<F as FnMutHKAResOpt<'a, FallibleLend<'a, Self>, Self::Error>>::B>, Self::Error>
The FallibleLender version of Iterator::find_map.
§Examples
let mut lender =
[1, 2, 3].into_iter().into_lender().into_fallible();
let found = lender.find_map(|x: i32| {
Ok(if x > 1 { Some(x * 10) } else { None })
});
assert_eq!(found, Ok(Some(20)));Sourcefn try_find<F, R>(
&mut self,
f: F,
) -> Result<ChangeOutputType<R, Option<FallibleLend<'_, Self>>>, Self::Error>
fn try_find<F, R>( &mut self, f: F, ) -> Result<ChangeOutputType<R, Option<FallibleLend<'_, Self>>>, Self::Error>
The FallibleLender version of Iterator::try_find.
§Examples
let mut lender =
lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let result =
lender.try_find(|&x| Ok(Some(*x > 1)));
assert_eq!(result, Ok(Some(Some(&2))));Sourcefn position<P>(&mut self, predicate: P) -> Result<Option<usize>, Self::Error>
fn position<P>(&mut self, predicate: P) -> Result<Option<usize>, Self::Error>
The FallibleLender version of Iterator::position.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.position(|&x| Ok(x == 2)), Ok(Some(1)));let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
assert_eq!(lender.position(|&x| Ok(x > 10)), Ok(None));Sourcefn rposition<P>(&mut self, predicate: P) -> Result<Option<usize>, Self::Error>where
P: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error>,
Self: Sized + ExactSizeFallibleLender + DoubleEndedFallibleLender,
fn rposition<P>(&mut self, predicate: P) -> Result<Option<usize>, Self::Error>where
P: FnMut(FallibleLend<'_, Self>) -> Result<bool, Self::Error>,
Self: Sized + ExactSizeFallibleLender + DoubleEndedFallibleLender,
The FallibleLender version of Iterator::rposition.
§Examples
let mut lender =
[1, 2, 3, 2, 1].iter().into_lender().into_fallible();
assert_eq!(
lender.rposition(|&x| Ok(x == 2)),
Ok(Some(3))
);Sourcefn max<T: Ord>(self) -> Result<Option<T>, Self::Error>
fn max<T: Ord>(self) -> Result<Option<T>, Self::Error>
The FallibleLender version of Iterator::max.
§Examples
let lender =
[1, 3, 2].into_iter().into_lender().into_fallible();
assert_eq!(lender.max(), Ok(Some(3)));Sourcefn min<T: Ord>(self) -> Result<Option<T>, Self::Error>
fn min<T: Ord>(self) -> Result<Option<T>, Self::Error>
The FallibleLender version of Iterator::min.
§Examples
let lender =
[3, 1, 2].into_iter().into_lender().into_fallible();
assert_eq!(lender.min(), Ok(Some(1)));Sourcefn max_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
fn max_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
The FallibleLender version of Iterator::max_by_key.
§Examples
let lender =
["a", "bbb", "cc"].into_iter().into_lender().into_fallible();
assert_eq!(lender.max_by_key(|s| Ok(s.len())), Ok(Some("bbb")));Sourcefn max_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error>,
fn max_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error>,
The FallibleLender version of Iterator::max_by.
§Examples
let lender =
["a", "bbb", "cc"].into_iter().into_lender().into_fallible();
assert_eq!(
lender.max_by(|x, y| Ok(x.len().cmp(&y.len()))),
Ok(Some("bbb"))
);Sourcefn min_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
fn min_by_key<B: Ord, T, F>(self, f: F) -> Result<Option<T>, Self::Error>
The FallibleLender version of Iterator::min_by_key.
§Examples
let lender =
["a", "bbb", "cc"].into_iter().into_lender().into_fallible();
assert_eq!(lender.min_by_key(|s| Ok(s.len())), Ok(Some("a")));Sourcefn min_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error>,
fn min_by<T, F>(self, compare: F) -> Result<Option<T>, Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: ToOwned<Owned = T>,
F: FnMut(&T, &FallibleLend<'_, Self>) -> Result<Ordering, Self::Error>,
The FallibleLender version of Iterator::min_by.
§Examples
let lender =
["a", "bbb", "cc"].into_iter().into_lender().into_fallible();
assert_eq!(
lender.min_by(|x, y| Ok(x.len().cmp(&y.len()))),
Ok(Some("a"))
);Sourcefn rev(self) -> Rev<Self>where
Self: Sized + DoubleEndedFallibleLender,
fn rev(self) -> Rev<Self>where
Self: Sized + DoubleEndedFallibleLender,
The FallibleLender version of Iterator::rev.
§Examples
let mut lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
)
.rev();
assert_eq!(lender.next(), Ok(Some(&3)));
assert_eq!(lender.next(), Ok(Some(&2)));
assert_eq!(lender.next(), Ok(Some(&1)));
assert_eq!(lender.next(), Ok(None));Sourcefn unzip<ExtA, ExtB>(self) -> Result<(ExtA, ExtB), Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: TupleLend<'all>,
ExtA: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <FirstShunt<Self> as IntoFallibleLender>::FallibleLender>>,
ExtB: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <SecondShunt<Self> as IntoFallibleLender>::FallibleLender>>,
fn unzip<ExtA, ExtB>(self) -> Result<(ExtA, ExtB), Self::Error>where
Self: Sized,
for<'all> FallibleLend<'all, Self>: TupleLend<'all>,
ExtA: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <FirstShunt<Self> as IntoFallibleLender>::FallibleLender>>,
ExtB: Default + for<'this> ExtendLender<NonFallibleAdapter<'this, <SecondShunt<Self> as IntoFallibleLender>::FallibleLender>>,
The FallibleLender version of Iterator::unzip.
Sourcefn copied<T>(self) -> Copied<Self> ⓘ
fn copied<T>(self) -> Copied<Self> ⓘ
The FallibleLender version of Iterator::copied.
Turns this FallibleLender into a
FallibleIterator.
§Examples
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut copied = lender.copied();
assert_eq!(copied.next()?, Some(1));
assert_eq!(copied.next()?, Some(2));
assert_eq!(copied.next()?, Some(3));
assert_eq!(copied.next()?, None);Sourcefn cloned<T>(self) -> Cloned<Self> ⓘ
fn cloned<T>(self) -> Cloned<Self> ⓘ
The FallibleLender version of Iterator::cloned.
Turns this FallibleLender into a
FallibleIterator.
§Examples
let lender = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2, 3].iter().into_fallible(),
);
let mut cloned = lender.cloned();
assert_eq!(cloned.next()?, Some(1));
assert_eq!(cloned.next()?, Some(2));
assert_eq!(cloned.next()?, Some(3));
assert_eq!(cloned.next()?, None);Sourcefn owned(self) -> Owned<Self> ⓘ
fn owned(self) -> Owned<Self> ⓘ
Turns this FallibleLender into a
FallibleIterator.
§Examples
let mut owned = [1, 2, 3].into_iter().into_lender().into_fallible().owned();
assert_eq!(owned.next()?, Some(1));
assert_eq!(owned.next()?, Some(2));
assert_eq!(owned.next()?, Some(3));
assert_eq!(owned.next()?, None);Sourcefn cycle(self) -> Cycle<Self>
fn cycle(self) -> Cycle<Self>
The FallibleLender version of Iterator::cycle.
§Examples
let mut cycled = [1, 2].iter().into_lender().into_fallible().cycle();
assert_eq!(cycled.next(), Ok(Some(&1)));
assert_eq!(cycled.next(), Ok(Some(&2)));
assert_eq!(cycled.next(), Ok(Some(&1)));
assert_eq!(cycled.next(), Ok(Some(&2)));Sourcefn sum<S>(self) -> Result<S, Self::Error>where
Self: Sized,
S: SumFallibleLender<Self>,
fn sum<S>(self) -> Result<S, Self::Error>where
Self: Sized,
S: SumFallibleLender<Self>,
The FallibleLender version of Iterator::sum.
Note: This method requires a type implementing
SumFallibleLender. For simple numeric
sums, consider using owned()
and then FallibleIterator::sum().
Sourcefn product<P>(self) -> Result<P, Self::Error>where
Self: Sized,
P: ProductFallibleLender<Self>,
fn product<P>(self) -> Result<P, Self::Error>where
Self: Sized,
P: ProductFallibleLender<Self>,
The FallibleLender version of Iterator::product.
Note: This method requires a type implementing
ProductFallibleLender. For simple
numeric products, consider using
owned() and then
FallibleIterator::product().
Sourcefn cmp<L>(self, other: L) -> Result<Ordering, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
L::FallibleLender: for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>>,
for<'all> FallibleLend<'all, Self>: Ord,
Self: Sized,
fn cmp<L>(self, other: L) -> Result<Ordering, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
L::FallibleLender: for<'all> FallibleLending<'all, Lend = FallibleLend<'all, Self>>,
for<'all> FallibleLend<'all, Self>: Ord,
Self: Sized,
The FallibleLender version of Iterator::cmp.
Note: Due to HRTB limitations, consider using
cmp_by instead.
§Examples
let a = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let b = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 3].iter().into_fallible(),
);
assert_eq!(a.cmp(b), Ok(Ordering::Less));Sourcefn cmp_by<L, F>(self, other: L, cmp: F) -> Result<Ordering, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Ordering, Self::Error>,
fn cmp_by<L, F>(self, other: L, cmp: F) -> Result<Ordering, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Ordering, Self::Error>,
The FallibleLender version of Iterator::cmp_by.
Note: the closure receives both lends under a single lifetime
(for<'all>). This is an HRTB limitation: the two lenders cannot
be advanced independently within the closure.
§Examples
let a = [1, 2, 3].into_iter().into_lender().into_fallible();
let b = [1, 2, 4].into_iter().into_lender().into_fallible();
assert_eq!(
a.cmp_by::<lender::IntoFallible<_>, _>(b, |x: i32, y: i32| Ok(x.cmp(&y))),
Ok(Ordering::Less)
);Sourcefn partial_cmp<L>(self, other: L) -> Result<Option<Ordering>, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn partial_cmp<L>(self, other: L) -> Result<Option<Ordering>, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::partial_cmp.
Note: Due to HRTB limitations, consider using
partial_cmp_by instead.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 3].into_iter().into_lender().into_fallible();
assert_eq!(
a.partial_cmp::<lender::IntoFallible<_>>(b),
Ok(Some(Ordering::Less))
);Sourcefn partial_cmp_by<L, F>(
self,
other: L,
partial_cmp: F,
) -> Result<Option<Ordering>, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Option<Ordering>, Self::Error>,
fn partial_cmp_by<L, F>(
self,
other: L,
partial_cmp: F,
) -> Result<Option<Ordering>, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<Option<Ordering>, Self::Error>,
The FallibleLender version of Iterator::partial_cmp_by.
See cmp_by for a note on the unified
lifetime constraint.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 3].into_iter().into_lender().into_fallible();
assert_eq!(
a.partial_cmp_by::<lender::IntoFallible<_>, _>(
b,
|x: i32, y: i32| Ok(x.partial_cmp(&y))
),
Ok(Some(Ordering::Less))
);Sourcefn eq<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn eq<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::eq.
Note: Due to HRTB limitations, consider using
eq_by instead.
Sourcefn eq_by<L, F>(self, other: L, eq: F) -> Result<bool, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<bool, Self::Error>,
fn eq_by<L, F>(self, other: L, eq: F) -> Result<bool, Self::Error>where
Self: Sized,
L: IntoFallibleLender<Error = Self::Error>,
F: for<'all> FnMut(FallibleLend<'all, Self>, FallibleLend<'all, L::FallibleLender>) -> Result<bool, Self::Error>,
The FallibleLender version of Iterator::eq_by.
See cmp_by for a note on the unified
lifetime constraint.
§Examples
let a = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
let b = lender::lend_fallible_iter::<fallible_lend!(&'lend i32), _>(
[1, 2].iter().into_fallible(),
);
assert_eq!(a.eq_by(b, |x, y| Ok(x == y)), Ok(true));Sourcefn ne<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn ne<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialEq<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::ne.
Note: Due to HRTB limitations, consider using
eq_by instead.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 3].into_iter().into_lender().into_fallible();
assert_eq!(a.ne::<lender::IntoFallible<_>>(b), Ok(true));Sourcefn lt<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn lt<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::lt.
Note: Due to HRTB limitations, consider using
partial_cmp_by instead.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 3].into_iter().into_lender().into_fallible();
assert_eq!(a.lt::<lender::IntoFallible<_>>(b), Ok(true));Sourcefn le<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn le<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::le.
Note: Due to HRTB limitations, consider using
partial_cmp_by instead.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 2].into_iter().into_lender().into_fallible();
assert_eq!(a.le::<lender::IntoFallible<_>>(b), Ok(true));Sourcefn gt<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn gt<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::gt.
Note: Due to HRTB limitations, consider using
partial_cmp_by instead.
§Examples
let a = [1, 3].into_iter().into_lender().into_fallible();
let b = [1, 2].into_iter().into_lender().into_fallible();
assert_eq!(a.gt::<lender::IntoFallible<_>>(b), Ok(true));Sourcefn ge<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
fn ge<L>(self, other: L) -> Result<bool, Self::Error>where
L: IntoFallibleLender<Error = Self::Error>,
for<'all> FallibleLend<'all, Self>: PartialOrd<FallibleLend<'all, L::FallibleLender>>,
Self: Sized,
The FallibleLender version of Iterator::ge.
Note: Due to HRTB limitations, consider using
partial_cmp_by instead.
§Examples
let a = [1, 2].into_iter().into_lender().into_fallible();
let b = [1, 2].into_iter().into_lender().into_fallible();
assert_eq!(a.ge::<lender::IntoFallible<_>>(b), Ok(true));Sourcefn is_sorted<T>(self) -> Result<bool, Self::Error>
fn is_sorted<T>(self) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::is_sorted.
§Examples
let lender = [1, 2, 3].into_iter().into_lender().into_fallible();
assert_eq!(lender.is_sorted(), Ok(true));
let lender = [1, 3, 2].into_iter().into_lender().into_fallible();
assert_eq!(lender.is_sorted(), Ok(false));Sourcefn is_sorted_by<T, F>(self, compare: F) -> Result<bool, Self::Error>
fn is_sorted_by<T, F>(self, compare: F) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::is_sorted_by.
§Examples
// Sorted in descending order.
let lender = [3, 2, 1].into_iter().into_lender().into_fallible();
assert_eq!(
lender.is_sorted_by(|a, b| Ok(b.partial_cmp(a))),
Ok(true)
);Sourcefn is_sorted_by_key<F, K>(self, f: F) -> Result<bool, Self::Error>
fn is_sorted_by_key<F, K>(self, f: F) -> Result<bool, Self::Error>
The FallibleLender version of Iterator::is_sorted_by_key.
§Examples
let lender =
["a", "bbb", "cc"].into_iter().into_lender().into_fallible();
assert_eq!(
lender.is_sorted_by_key(|s| Ok(s.len())),
Ok(false)
);
let lender =
["a", "cc", "bbb"].into_iter().into_lender().into_fallible();
assert_eq!(
lender.is_sorted_by_key(|s| Ok(s.len())),
Ok(true)
);Sourcefn chunky(self, chunk_size: usize) -> Chunky<Self>where
Self: Sized + ExactSizeFallibleLender,
fn chunky(self, chunk_size: usize) -> Chunky<Self>where
Self: Sized + ExactSizeFallibleLender,
A lending replacement for Iterator::array_chunks.
This method returns a lender that yields lenders returning the next
chunk_size lends.
§Panics
Panics if chunk_size is zero.
§Examples
let data = [1, 2, 3, 4, 5];
let lender = data.iter().into_lender().into_fallible();
let mut chunky = lender.chunky(2);
let mut chunk1 = chunky.next().unwrap().unwrap();
assert_eq!(chunk1.next().unwrap(), Some(&1));
assert_eq!(chunk1.next().unwrap(), Some(&2));
assert_eq!(chunk1.next().unwrap(), None);
let mut chunk2 = chunky.next().unwrap().unwrap();
assert_eq!(chunk2.next().unwrap(), Some(&3));
assert_eq!(chunk2.next().unwrap(), Some(&4));
assert_eq!(chunk2.next().unwrap(), None);
let mut chunk3 = chunky.next().unwrap().unwrap();
assert_eq!(chunk3.next().unwrap(), Some(&5));
assert_eq!(chunk3.next().unwrap(), None);Sourcefn iter<'this>(self) -> Iter<'this, Self> ⓘwhere
Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this,
fn iter<'this>(self) -> Iter<'this, Self> ⓘwhere
Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this,
Turns this FallibleLender into a
FallibleIterator where it has
already fulfilled the requirements of the
FallibleIterator trait.
Note: Due to HRTB limitations, consider using
copied, cloned,
or owned instead when applicable.
§Examples
let lender =
[1, 2, 3].into_iter().into_lender().into_fallible();
let v: Vec<i32> = lender.iter().collect().unwrap();
assert_eq!(v, vec![1, 2, 3]);Sourcefn lender_by_ref<'this>(self) -> FromFallibleIterRef<Iter<'this, Self>>where
Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this,
fn lender_by_ref<'this>(self) -> FromFallibleIterRef<Iter<'this, Self>>where
Self: Sized + 'this,
for<'all> FallibleLend<'all, Self>: 'this,
Turns this FallibleLender into a new
FallibleLender that lends references to the items
of the original lender.
This is a convenience for self.iter().into_fallible_ref_lender():
first, iter converts this lender into a
FallibleIterator; then,
into_fallible_ref_lender
wraps it back into a FallibleLender that stores each element and
lends a reference to it.
The resulting lender has
FallibleLend<'lend> = &'lend FallibleLend<'this, Self>.
§Examples
let mut lender =
[1, 2, 3].into_iter().into_lender()
.into_fallible().lender_by_ref();
let item: &i32 =
lender.next().unwrap().unwrap();
assert_eq!(*item, 1);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.