about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2018-01-03 01:01:40 +0200
committerSebastian Dröge <sebastian@centricular.com>2018-01-13 12:18:57 +0200
commit6bf1dfdd76625ba753de0d1b87a2825606cf6f2b (patch)
tree2a3850dda7ea3163d4d0a3a925332b410d7c7231
parentcea36f447ea746397003f1ee98ee41e858b1951b (diff)
downloadrust-6bf1dfdd76625ba753de0d1b87a2825606cf6f2b.tar.gz
rust-6bf1dfdd76625ba753de0d1b87a2825606cf6f2b.zip
Implement TrustedRandomAccess for slice::{ExactChunks, ExactChunksMut}
-rw-r--r--src/libcore/slice/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index c61d17290c8..9379a064a6c 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -2484,6 +2484,15 @@ impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> {
 #[unstable(feature = "fused", issue = "35602")]
 impl<'a, T> FusedIterator for ExactChunks<'a, T> {}
 
+#[doc(hidden)]
+unsafe impl<'a, T> TrustedRandomAccess for ExactChunks<'a, T> {
+    unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T] {
+        let start = i * self.chunk_size;
+        from_raw_parts(self.v.as_ptr().offset(start as isize), self.chunk_size)
+    }
+    fn may_have_side_effect() -> bool { false }
+}
+
 /// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size`
 /// elements at a time). When the slice len is not evenly divided by the chunk
 /// size, the last up to `chunk_size-1` elements will be omitted.
@@ -2572,6 +2581,15 @@ impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> {
 #[unstable(feature = "fused", issue = "35602")]
 impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {}
 
+#[doc(hidden)]
+unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
+    unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut [T] {
+        let start = i * self.chunk_size;
+        from_raw_parts_mut(self.v.as_mut_ptr().offset(start as isize), self.chunk_size)
+    }
+    fn may_have_side_effect() -> bool { false }
+}
+
 //
 // Free functions
 //