TrustedLen

Trait TrustedLen 

Source
pub unsafe trait TrustedLen: Iterator { }
🔬This is a nightly-only experimental API. (trusted_len #37572)
Expand description

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§

Source§

impl TrustedLen for ToLowercase

Available on non-crate feature ferrocene_certified only.
Source§

impl TrustedLen for ToUppercase

Available on non-crate feature ferrocene_certified only.
Source§

impl TrustedLen for Bytes<'_>

Available on non-crate feature ferrocene_certified only.
Source§

impl<'a, I, T> TrustedLen for Cloned<I>
where I: TrustedLen<Item = &'a T>, T: Clone + 'a,

1.36.0 · Source§

impl<'a, I, T> TrustedLen for Copied<I>
where I: TrustedLen<Item = &'a T>, T: Copy + 'a,

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::option::IntoIter<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::option::Iter<'_, A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::option::IterMut<'_, A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::result::IntoIter<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::result::Iter<'_, A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A> TrustedLen for core::result::IterMut<'_, A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A, B> TrustedLen for Chain<A, B>
where A: TrustedLen, B: TrustedLen<Item = A::Item>,

Available on non-crate feature ferrocene_certified only.
Source§

impl<A, B> TrustedLen for Zip<A, B>
where A: TrustedLen, B: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F>

Available on non-crate feature ferrocene_certified only.
1.43.0 · Source§

impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: Clone> TrustedLen for Repeat<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: Clone> TrustedLen for RepeatN<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for Range<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for RangeFrom<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for RangeInclusive<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for IterRange<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for IterRangeFrom<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<A: TrustedStep> TrustedLen for IterRangeInclusive<A>

Available on non-crate feature ferrocene_certified only.
Source§

impl<B, I, F> TrustedLen for Map<I, F>
where I: TrustedLen, F: FnMut(I::Item) -> B,

Source§

impl<I> TrustedLen for Enumerate<I>
where I: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for Flatten<I>
where I: Iterator<Item: IntoIterator>, FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for Fuse<I>
where I: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for Peekable<I>
where I: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for Rev<I>

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for Skip<I>
where I: Iterator + TrustedRandomAccess,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I> TrustedLen for StepBy<I>
where I: Iterator + TrustedRandomAccess,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I, U, F> TrustedLen for FlatMap<I, U, F>
where I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U, FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>: TrustedLen,

Available on non-crate feature ferrocene_certified only.
Source§

impl<I: TrustedLen + ?Sized> TrustedLen for &mut I

Source§

impl<I: TrustedLen> TrustedLen for Take<I>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for Chunks<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for ChunksExact<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for ChunksExactMut<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for ChunksMut<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for core::slice::Iter<'_, T>

Source§

impl<T> TrustedLen for core::slice::IterMut<'_, T>

Source§

impl<T> TrustedLen for RChunks<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for RChunksExact<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for RChunksExactMut<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for RChunksMut<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for Windows<'_, T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for Empty<T>

Available on non-crate feature ferrocene_certified only.
Source§

impl<T> TrustedLen for Once<T>

Available on non-crate feature ferrocene_certified only.
1.40.0 · Source§

impl<T, const N: usize> TrustedLen for core::array::IntoIter<T, N>

Available on non-crate feature ferrocene_certified only.