impl TrustedRandomAccess for ArrayWindows
(cherry picked from commit 129d552d3f)
This commit is contained in:
parent
8011d42521
commit
e1dd1bb6cb
1 changed files with 18 additions and 0 deletions
|
|
@ -2232,6 +2232,14 @@ impl<'a, T, const N: usize> Iterator for ArrayWindows<'a, T, N> {
|
|||
fn last(self) -> Option<Self::Item> {
|
||||
self.v.last_chunk()
|
||||
}
|
||||
|
||||
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
|
||||
// SAFETY: since the caller guarantees that `idx` is in bounds,
|
||||
// which means that `idx` cannot overflow an `isize`, and the
|
||||
// "slice" created by `cast_array` is a subslice of `self.v`
|
||||
// thus is guaranteed to be valid for the lifetime `'a` of `self.v`.
|
||||
unsafe { &*self.v.as_ptr().add(idx).cast_array() }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "array_windows", since = "1.94.0")]
|
||||
|
|
@ -2266,6 +2274,16 @@ unsafe impl<T, const N: usize> TrustedLen for ArrayWindows<'_, T, N> {}
|
|||
#[stable(feature = "array_windows", since = "1.94.0")]
|
||||
impl<T, const N: usize> FusedIterator for ArrayWindows<'_, T, N> {}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "trusted_random_access", issue = "none")]
|
||||
unsafe impl<T, const N: usize> TrustedRandomAccess for ArrayWindows<'_, T, N> {}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "trusted_random_access", issue = "none")]
|
||||
unsafe impl<T, const N: usize> TrustedRandomAccessNoCoerce for ArrayWindows<'_, T, N> {
|
||||
const MAY_HAVE_SIDE_EFFECT: bool = false;
|
||||
}
|
||||
|
||||
/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
|
||||
/// time), starting at the end of the slice.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue