Trait TrustedRandomAccess
pub unsafe trait TrustedRandomAccess: TrustedRandomAccessNoCoerce
An iterator whose items are random-accessible efficiently
Safety
The iterator's size_hint must be exact and cheap to call.
TrustedRandomAccessNoCoerce::size may not be overridden.
All subtypes and all supertypes of Self must also implement TrustedRandomAccess.
In particular, this means that types with non-invariant parameters usually can not have
an impl for TrustedRandomAccess that depends on any trait bounds on such parameters, except
for bounds that come from the respective struct/enum definition itself, or bounds involving
traits that themselves come with a guarantee similar to this one.
If Self: ExactSizeIterator then self.len() must always produce results consistent
with self.size().
If Self: Iterator, then <Self as Iterator>::__iterator_get_unchecked(&mut self, idx)
must be safe to call provided the following conditions are met.
0 <= idxandidx < self.size().- If
Self: !Clone, thenself.__iterator_get_unchecked(idx)is never called with the same index onselfmore than once. - After
self.__iterator_get_unchecked(idx)has been called, thenself.next_back()will only be called at mostself.size() - idx - 1times. IfSelf: Cloneandselfis cloned, then this number is calculated forselfand its clone individually, butself.next_back()calls that happened before the cloning count for bothselfand the clone. - After
self.__iterator_get_unchecked(idx)has been called, then only the following methods will be called onselfor on any new clones ofself:std::clone::Clone::clonestd::iter::Iterator::size_hintstd::iter::DoubleEndedIterator::next_backstd::iter::ExactSizeIterator::lenstd::iter::Iterator::__iterator_get_uncheckedstd::iter::TrustedRandomAccessNoCoerce::size
- If
Selfis a subtype ofT, thenselfis allowed to be coerced toT. Ifselfis coerced toTafterself.__iterator_get_unchecked(idx)has already been called, then no methods except for the ones listed under 4. are allowed to be called on the resulting value of typeT, either. Multiple such coercion steps are allowed. Regarding 2. and 3., the number of times__iterator_get_unchecked(idx)ornext_back()is called onselfand the resulting value of typeT(and on further coercion results with super-supertypes) are added together and their sums must not exceed the specified bounds.
Further, given that these conditions are met, it must guarantee that:
- It does not change the value returned from
size_hint - It must be safe to call the methods listed above on
selfafter callingself.__iterator_get_unchecked(idx), assuming that the required traits are implemented. - It must also be safe to drop
selfafter callingself.__iterator_get_unchecked(idx). - If
Selfis a subtype ofT, then it must be safe to coerceselftoT.
Implementors
impl TrustedRandomAccess for Bytes<'_>impl TrustedRandomAccess for CaseMappingIterimpl TrustedRandomAccess for Range<NonZero<u16>>impl TrustedRandomAccess for Range<NonZero<u32>>impl TrustedRandomAccess for Range<NonZero<u64>>impl TrustedRandomAccess for Range<NonZero<u8>>impl TrustedRandomAccess for Range<NonZero<usize>>impl TrustedRandomAccess for Range<i16>impl TrustedRandomAccess for Range<i32>impl TrustedRandomAccess for Range<i64>impl TrustedRandomAccess for Range<i8>impl TrustedRandomAccess for Range<isize>impl TrustedRandomAccess for Range<u16>impl TrustedRandomAccess for Range<u32>impl TrustedRandomAccess for Range<u64>impl TrustedRandomAccess for Range<u8>impl TrustedRandomAccess for Range<usize>impl TrustedRandomAccess for RangeIter<i16>impl TrustedRandomAccess for RangeIter<i32>impl TrustedRandomAccess for RangeIter<i64>impl TrustedRandomAccess for RangeIter<i8>impl TrustedRandomAccess for RangeIter<isize>impl TrustedRandomAccess for RangeIter<u16>impl TrustedRandomAccess for RangeIter<u32>impl TrustedRandomAccess for RangeIter<u64>impl TrustedRandomAccess for RangeIter<u8>impl TrustedRandomAccess for RangeIter<usize>impl TrustedRandomAccess for ToCasefoldimpl TrustedRandomAccess for ToLowercaseimpl TrustedRandomAccess for ToTitlecaseimpl TrustedRandomAccess for ToUppercaseimpl<'a, T> TrustedRandomAccess for Chunks<'a, T>impl<'a, T> TrustedRandomAccess for ChunksExact<'a, T>impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T>impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T>impl<'a, T> TrustedRandomAccess for Iter<'a, T>impl<'a, T> TrustedRandomAccess for IterMut<'a, T>impl<'a, T> TrustedRandomAccess for RChunks<'a, T>impl<'a, T> TrustedRandomAccess for RChunksExact<'a, T>impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T>impl<'a, T> TrustedRandomAccess for RChunksMut<'a, T>impl<'a, T> TrustedRandomAccess for Windows<'a, T>impl<A, B> TrustedRandomAccess for Zip<A, B> where A: TrustedRandomAccess, B: TrustedRandomAccess,impl<I> TrustedRandomAccess for Cloned<I> where I: TrustedRandomAccess,impl<I> TrustedRandomAccess for Copied<I> where I: TrustedRandomAccess,impl<I> TrustedRandomAccess for Enumerate<I> where I: TrustedRandomAccess,impl<I> TrustedRandomAccess for Fuse<I> where I: TrustedRandomAccess,impl<I> TrustedRandomAccess for Skip<I> where I: TrustedRandomAccess,impl<I, F> TrustedRandomAccess for Map<I, F> where I: TrustedRandomAccess,impl<T, const N: usize> TrustedRandomAccess for ArrayWindows<'_, T, N>