|
1 | 1 | use crate::cmp;
|
2 |
| -use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen}; |
| 2 | +use crate::iter::{ |
| 3 | + adapters::zip::try_get_unchecked, adapters::SourceIter, FusedIterator, InPlaceIterable, |
| 4 | + TrustedLen, TrustedRandomAccess, |
| 5 | +}; |
3 | 6 | use crate::ops::{ControlFlow, Try};
|
4 | 7 |
|
5 | 8 | /// An iterator that only iterates over the first `n` iterations of `iter`.
|
@@ -111,6 +114,15 @@ where
|
111 | 114 |
|
112 | 115 | self.try_fold(init, ok(fold)).unwrap()
|
113 | 116 | }
|
| 117 | + |
| 118 | + unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <I as Iterator>::Item |
| 119 | + where |
| 120 | + Self: TrustedRandomAccess, |
| 121 | + { |
| 122 | + // SAFETY: the caller must uphold the contract for |
| 123 | + // `Iterator::__iterator_get_unchecked`. |
| 124 | + unsafe { try_get_unchecked(&mut self.iter, idx) } |
| 125 | + } |
114 | 126 | }
|
115 | 127 |
|
116 | 128 | #[unstable(issue = "none", feature = "inplace_iteration")]
|
@@ -207,3 +219,12 @@ impl<I> FusedIterator for Take<I> where I: FusedIterator {}
|
207 | 219 |
|
208 | 220 | #[unstable(feature = "trusted_len", issue = "37572")]
|
209 | 221 | unsafe impl<I: TrustedLen> TrustedLen for Take<I> {}
|
| 222 | + |
| 223 | +#[doc(hidden)] |
| 224 | +#[unstable(feature = "trusted_random_access", issue = "none")] |
| 225 | +unsafe impl<I> TrustedRandomAccess for Take<I> |
| 226 | +where |
| 227 | + I: TrustedRandomAccess, |
| 228 | +{ |
| 229 | + const MAY_HAVE_SIDE_EFFECT: bool = I::MAY_HAVE_SIDE_EFFECT; |
| 230 | +} |
0 commit comments