pub unsafe trait TrustedLen: Iterator { }
🔬This is a nightly-only experimental API. (trusted_len)
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 Bytes<'_>

source§

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

1.36.0 · source§

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

source§

impl<'a, T, I, F, const N: usize> TrustedLen for FlatMap<I, &'a [T; N], F>where I: TrustedLen, F: FnMut(<I as Iterator>::Item) -> &'a [T; N],

source§

impl<'a, T, I, F, const N: usize> TrustedLen for FlatMap<I, &'a mut [T; N], F>where I: TrustedLen, F: FnMut(<I as Iterator>::Item) -> &'a mut [T; N],

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

1.43.0 · source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<I> TrustedLen for Flatten<I>where I: TrustedLen, <I as Iterator>::Item: TrustedConstSize,

source§

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

source§

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

source§

impl<I> TrustedLen for Rev<I>where I: TrustedLen + DoubleEndedIterator,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<T> TrustedLen for wasmer_types::lib::std::slice::Iter<'_, T>

source§

impl<T> TrustedLen for wasmer_types::lib::std::slice::IterMut<'_, T>

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<T> TrustedLen for DrainSorted<'_, T>where T: Ord,

source§

impl<T> TrustedLen for IntoIterSorted<T>where T: Ord,

source§

impl<T> TrustedLen for alloc::collections::vec_deque::iter::Iter<'_, T>

source§

impl<T> TrustedLen for alloc::collections::vec_deque::iter_mut::IterMut<'_, T>

source§

impl<T> TrustedLen for Empty<T>

source§

impl<T> TrustedLen for Once<T>

source§

impl<T, A> TrustedLen for Drain<'_, T, A>where A: Allocator,

source§

impl<T, A> TrustedLen for wasmer_types::lib::std::vec::IntoIter<T, A>where A: Allocator,

source§

impl<T, A> TrustedLen for alloc::collections::vec_deque::into_iter::IntoIter<T, A>where A: Allocator,

source§

impl<T, I, F, const N: usize> TrustedLen for FlatMap<I, [T; N], F>where I: TrustedLen, F: FnMut(<I as Iterator>::Item) -> [T; N],

source§

impl<T, const N: usize> TrustedLen for ArrayChunks<'_, T, N>

source§

impl<T, const N: usize> TrustedLen for ArrayChunksMut<'_, T, N>

1.40.0 · source§

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