pub unsafe trait TrustedLen: Iterator { }Expand description
Trait for all types which have a known upper-bound.
Functions that receive a TrustedLen iterator can assume that it’s size_hint is exact,
and can pre-allocate memory, unroll loops, or otherwise optimize their implementations
accordingly.
§Safety
The type which implements this trait must provide an exact Some upper-bound for its
size_hint method. Failure to do so can trigger undefined behavior in users of the trait.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl TrustedLen for Range<i8>
impl TrustedLen for Range<i16>
impl TrustedLen for Range<i32>
impl TrustedLen for Range<i64>
impl TrustedLen for Range<u8>
impl TrustedLen for Range<u16>
impl TrustedLen for Range<u32>
impl TrustedLen for Range<u64>
impl TrustedLen for Range<usize>
impl TrustedLen for RangeInclusive<i8>
impl TrustedLen for RangeInclusive<i16>
impl TrustedLen for RangeInclusive<i32>
impl TrustedLen for RangeInclusive<i64>
impl TrustedLen for RangeInclusive<u8>
impl TrustedLen for RangeInclusive<u16>
impl TrustedLen for RangeInclusive<u32>
impl TrustedLen for RangeInclusive<u64>
impl TrustedLen for RangeInclusive<usize>
impl TrustedLen for StepBy<Range<i8>>
impl TrustedLen for StepBy<Range<i16>>
impl TrustedLen for StepBy<Range<i32>>
impl TrustedLen for StepBy<Range<i64>>
impl TrustedLen for StepBy<Range<u8>>
impl TrustedLen for StepBy<Range<u16>>
impl TrustedLen for StepBy<Range<u32>>
impl TrustedLen for StepBy<Range<u64>>
impl TrustedLen for StepBy<Range<usize>>
impl TrustedLen for StepBy<RangeInclusive<i8>>
impl TrustedLen for StepBy<RangeInclusive<i16>>
impl TrustedLen for StepBy<RangeInclusive<i32>>
impl TrustedLen for StepBy<RangeInclusive<i64>>
impl TrustedLen for StepBy<RangeInclusive<u8>>
impl TrustedLen for StepBy<RangeInclusive<u16>>
impl TrustedLen for StepBy<RangeInclusive<u32>>
impl TrustedLen for StepBy<RangeInclusive<u64>>
impl TrustedLen for StepBy<RangeInclusive<usize>>
impl<'a, I, T: 'a, E: 'a> TrustedLen for ProcessResults<'a, I, E>where
I: TrustedLen<Item = Result<T, E>>,
impl<'a, I, T> TrustedLen for Cloned<I>
impl<'a, I, T> TrustedLen for Copied<I>
impl<B, I, F> TrustedLen for Map<I, F>
impl<I, T> TrustedLen for Enumerate<I>where
I: TrustedLen<Item = T>,
impl<I> TrustedLen for Skip<I>where
I: TrustedLen,
impl<T, U> TrustedLen for Zip<T, U>where
T: TrustedLen,
U: TrustedLen,
A Zip is only TrustedLen when both halves are, so it cannot be built from an iterator
without an exact upper bound, such as std::iter::repeat:
ⓘ
use vortex_buffer::trusted_len::TrustedLen;
fn assert_trusted_len<I: TrustedLen>(_: I) {}
assert_trusted_len([1u8, 2, 3].into_iter().zip(std::iter::repeat(0u8)));Bound the other half instead, e.g. with std::iter::repeat_n:
use vortex_buffer::trusted_len::TrustedLen;
fn assert_trusted_len<I: TrustedLen>(_: I) {}
assert_trusted_len([1u8, 2, 3].into_iter().zip(std::iter::repeat_n(0u8, 3)));