On this page
Trait std::iter::TrustedLen
pub unsafe trait TrustedLen: Iterator { }
trusted_len
#37572)
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 TrustedLen for Bytes<'_>
impl TrustedLen for StepBy<Range<u8>>
Safety: This macro is only applied to ranges over types <= usize which means the inner length is guaranteed to fit into a usize and so the outer length calculation won’t encounter clamped values
impl TrustedLen for StepBy<Range<u16>>
Safety: This macro is only applied to ranges over types <= usize which means the inner length is guaranteed to fit into a usize and so the outer length calculation won’t encounter clamped values
impl TrustedLen for StepBy<Range<u32>>
Safety: This macro is only applied to ranges over types <= usize which means the inner length is guaranteed to fit into a usize and so the outer length calculation won’t encounter clamped values
impl TrustedLen for StepBy<Range<u64>>
Safety: This macro is only applied to ranges over types <= usize which means the inner length is guaranteed to fit into a usize and so the outer length calculation won’t encounter clamped values
impl TrustedLen for StepBy<Range<usize>>
Safety: This macro is only applied to ranges over types <= usize which means the inner length is guaranteed to fit into a usize and so the outer length calculation won’t encounter clamped values
impl<'a, I, T> TrustedLen for Cloned<I>
where
T: 'a + Clone,
I: TrustedLen<Item = &'a T>,
impl<'a, I, T> TrustedLen for Copied<I>
where
T: 'a + Copy,
I: TrustedLen<Item = &'a T>,
impl<A> TrustedLen for Range<A>
where
A: TrustedStep,
impl<A> TrustedLen for RangeFrom<A>
where
A: TrustedStep,
impl<A> TrustedLen for RangeInclusive<A>
where
A: TrustedStep,
impl<A> TrustedLen for std::option::IntoIter<A>
impl<A> TrustedLen for std::option::Iter<'_, A>
impl<A> TrustedLen for std::option::IterMut<'_, A>
impl<A> TrustedLen for std::result::IntoIter<A>
impl<A> TrustedLen for std::result::Iter<'_, A>
impl<A> TrustedLen for std::result::IterMut<'_, A>
impl<A> TrustedLen for Repeat<A>
where
A: Clone,
impl<A, B> TrustedLen for Chain<A, B>
where
A: TrustedLen,
B: TrustedLen<Item = <A as Iterator>::Item>,
impl<A, B> TrustedLen for Zip<A, B>
where
A: TrustedLen,
B: TrustedLen,
impl<A, F> TrustedLen for OnceWith<F>
where
F: FnOnce() -> A,
impl<A, F> TrustedLen for RepeatWith<F>
where
F: FnMut() -> A,
impl<B, I, F> TrustedLen for Map<I, F>
where
I: TrustedLen,
F: FnMut(<I as Iterator>::Item) -> B,
impl<I> TrustedLen for &mut I
where
I: TrustedLen + ?Sized,
impl<I> TrustedLen for Enumerate<I>
where
I: TrustedLen,
impl<I> TrustedLen for Flatten<I>
where
I: Iterator,
<I as Iterator>::Item: IntoIterator,
FlattenCompat<I, <<I as Iterator>::Item as IntoIterator>::IntoIter>: TrustedLen,
impl<I> TrustedLen for Fuse<I>
where
I: TrustedLen,
impl<I> TrustedLen for Peekable<I>
where
I: TrustedLen,
impl<I> TrustedLen for Rev<I>
where
I: TrustedLen + DoubleEndedIterator,
impl<I> TrustedLen for Take<I>
where
I: TrustedLen,
impl<I, U, F> TrustedLen for FlatMap<I, U, F>
where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>: TrustedLen,
impl<T> TrustedLen for std::collections::vec_deque::Iter<'_, T>
impl<T> TrustedLen for std::collections::vec_deque::IterMut<'_, T>
impl<T> TrustedLen for Chunks<'_, T>
impl<T> TrustedLen for ChunksExact<'_, T>
impl<T> TrustedLen for ChunksExactMut<'_, T>
impl<T> TrustedLen for ChunksMut<'_, T>
impl<T> TrustedLen for std::slice::Iter<'_, T>
impl<T> TrustedLen for std::slice::IterMut<'_, T>
impl<T> TrustedLen for RChunks<'_, T>
impl<T> TrustedLen for RChunksExact<'_, T>
impl<T> TrustedLen for RChunksExactMut<'_, T>
impl<T> TrustedLen for RChunksMut<'_, T>
impl<T> TrustedLen for Windows<'_, T>
impl<T> TrustedLen for Empty<T>
impl<T> TrustedLen for Once<T>
impl<T, A> TrustedLen for DrainSorted<'_, T, A>
where
T: Ord,
A: Allocator,
impl<T, A> TrustedLen for IntoIterSorted<T, A>
where
T: Ord,
A: Allocator,
impl<T, A> TrustedLen for std::collections::vec_deque::IntoIter<T, A>
where
A: Allocator,
impl<T, A> TrustedLen for Drain<'_, T, A>
where
A: Allocator,
impl<T, A> TrustedLen for std::vec::IntoIter<T, A>
where
A: Allocator,
impl<T, const N: usize> TrustedLen for std::array::IntoIter<T, N>
impl<T, const N: usize> TrustedLen for ArrayChunks<'_, T, N>
impl<T, const N: usize> TrustedLen for ArrayChunksMut<'_, T, N>
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/iter/trait.TrustedLen.html