Trait TrustedLen
unsafe trait TrustedLen: Iterator
An iterator that reports an accurate length using size_hint.
The iterator reports a size hint where it is either exact
(lower bound is equal to upper bound), or the upper bound is None.
The upper bound must only be None if the actual iterator length is
larger than usize::MAX. In that case, the lower bound must be
usize::MAX, resulting in an [Iterator::size_hint()] of
(usize::MAX, None).
The iterator must produce exactly the number of elements it reported or diverge before reaching the end.
When shouldn't an adapter be TrustedLen?
If an adapter makes an iterator shorter by a given amount, then it's
usually incorrect for that adapter to implement TrustedLen. The inner
iterator might return more than usize::MAX items, but there's no way to
know what k elements less than that will be, since the size_hint from
the inner iterator has already saturated and lost that information.
This is why Skip<I> isn't TrustedLen, even when
I implements TrustedLen.
Safety
This trait must only be implemented when the contract is upheld. Consumers
of this trait must inspect [Iterator::size_hint()]’s upper bound.
Implementors
impl<T> TrustedLen for IterMut<'_, T>impl<T> TrustedLen for Empty<T>impl<T, N: usize> TrustedLen for ArrayWindows<'_, T, N>impl<I> TrustedLen for Enumerate<I>impl<A: Clone> TrustedLen for RepeatN<A>impl<T, N: usize> TrustedLen for IntoIter<T, N>impl<I, U, F> TrustedLen for FlatMap<I, U, F>impl<I> TrustedLen for Rev<I>impl<A: TrustedStep> TrustedLen for RangeIter<A>impl<T> TrustedLen for Iter<'_, T>impl<T> TrustedLen for ChunksExactMut<'_, T>impl TrustedLen for Bytes<'_>impl<A: TrustedStep> TrustedLen for Range<A>impl<I> TrustedLen for Skip<I>impl TrustedLen for ToLowercaseimpl<A: Clone> TrustedLen for Repeat<A>impl<A: TrustedLen> TrustedLen for OptionFlatten<A>impl<A> TrustedLen for IntoIter<A>impl<T> TrustedLen for ChunksExact<'_, T>impl<A: TrustedStep> TrustedLen for RangeInclusive<A>impl<T> TrustedLen for RChunksExactMut<'_, T>impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F>impl<A, B> TrustedLen for Zip<A, B>impl TrustedLen for ToUppercaseimpl<A> TrustedLen for IntoIter<A>impl<A> TrustedLen for IterMut<'_, A>impl<I> TrustedLen for Peekable<I>impl<T> TrustedLen for ChunksMut<'_, T>impl<T> TrustedLen for RChunksExact<'_, T>impl<A: TrustedStep> TrustedLen for RangeFrom<A>impl<'a, I, T> TrustedLen for Copied<I>impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F>impl<'a, I, T> TrustedLen for Cloned<I>impl<B, I, F> TrustedLen for Map<I, F>impl<A> TrustedLen for IterMut<'_, A>impl<A> TrustedLen for Iter<'_, A>impl<T> TrustedLen for Chunks<'_, T>impl<T> TrustedLen for RChunksMut<'_, T>impl<I> TrustedLen for StepBy<I>impl<A, B> TrustedLen for Chain<A, B>impl<I> TrustedLen for Fuse<I>impl<I> TrustedLen for Flatten<I>impl<A> TrustedLen for Iter<'_, A>impl<A: TrustedStep> TrustedLen for RangeFromIter<A>impl<T> TrustedLen for Windows<'_, T>impl TrustedLen for ToTitlecaseimpl<T> TrustedLen for RChunks<'_, T>impl<I: TrustedLen> TrustedLen for Take<I>impl<I: TrustedLen + ?Sized> TrustedLen for &mut Iimpl<A: TrustedStep> TrustedLen for RangeInclusiveIter<A>impl<T> TrustedLen for Once<T>