]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/iter/adapters/zip.rs
Split iterator adaptors into individual modules
[rust.git] / library / core / src / iter / adapters / zip.rs
index a854f70dcd0bac5a5371f16857058e943587b043..fdc4035a612f191d751292eb513a17db5d73aea8 100644 (file)
@@ -1,9 +1,10 @@
-use crate::cmp;
-use crate::fmt::{self, Debug};
-
-use super::super::{
-    DoubleEndedIterator, ExactSizeIterator, FusedIterator, InPlaceIterable, Iterator, SourceIter,
-    TrustedLen,
+use crate::{
+    cmp,
+    fmt::{self, Debug},
+    iter::{
+        DoubleEndedIterator, ExactSizeIterator, FusedIterator, InPlaceIterable, Iterator,
+        SourceIter, TrustedLen,
+    },
 };
 
 /// An iterator that iterates two other iterators simultaneously.
@@ -21,7 +22,7 @@ pub struct Zip<A, B> {
     len: usize,
 }
 impl<A: Iterator, B: Iterator> Zip<A, B> {
-    pub(in super::super) fn new(a: A, b: B) -> Zip<A, B> {
+    pub(in crate::iter) fn new(a: A, b: B) -> Zip<A, B> {
         ZipImpl::new(a, b)
     }
     fn super_nth(&mut self, mut n: usize) -> Option<(A::Item, B::Item)> {
@@ -59,12 +60,12 @@ fn nth(&mut self, n: usize) -> Option<Self::Item> {
     }
 
     #[inline]
-    unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item
+    unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
     where
         Self: TrustedRandomAccess,
     {
-        // SAFETY: `ZipImpl::get_unchecked` has same safety requirements as
-        // `Iterator::get_unchecked`.
+        // SAFETY: `ZipImpl::__iterator_get_unchecked` has same safety
+        // requirements as `Iterator::__iterator_get_unchecked`.
         unsafe { ZipImpl::get_unchecked(self, idx) }
     }
 }
@@ -93,7 +94,7 @@ fn next_back(&mut self) -> Option<Self::Item>
     where
         A: DoubleEndedIterator + ExactSizeIterator,
         B: DoubleEndedIterator + ExactSizeIterator;
-    // This has the same safety requirements as `Iterator::get_unchecked`
+    // This has the same safety requirements as `Iterator::__iterator_get_unchecked`
     unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
     where
         Self: Iterator + TrustedRandomAccess;
@@ -197,12 +198,14 @@ fn next(&mut self) -> Option<(A::Item, B::Item)> {
             let i = self.index;
             self.index += 1;
             // SAFETY: `i` is smaller than `self.len`, thus smaller than `self.a.len()` and `self.b.len()`
-            unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
+            unsafe {
+                Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
+            }
         } else if A::may_have_side_effect() && self.index < self.a.size() {
             // match the base implementation's potential side effects
             // SAFETY: we just checked that `self.index` < `self.a.len()`
             unsafe {
-                self.a.get_unchecked(self.index);
+                self.a.__iterator_get_unchecked(self.index);
             }
             self.index += 1;
             None
@@ -229,13 +232,13 @@ fn nth(&mut self, n: usize) -> Option<Self::Item> {
                 // ensures that `end` is smaller than or equal to `self.len`,
                 // so `i` is also smaller than `self.len`.
                 unsafe {
-                    self.a.get_unchecked(i);
+                    self.a.__iterator_get_unchecked(i);
                 }
             }
             if B::may_have_side_effect() {
                 // SAFETY: same as above.
                 unsafe {
-                    self.b.get_unchecked(i);
+                    self.b.__iterator_get_unchecked(i);
                 }
             }
         }
@@ -277,7 +280,9 @@ fn next_back(&mut self) -> Option<(A::Item, B::Item)>
             let i = self.len;
             // SAFETY: `i` is smaller than the previous value of `self.len`,
             // which is also smaller than or equal to `self.a.len()` and `self.b.len()`
-            unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
+            unsafe {
+                Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
+            }
         } else {
             None
         }
@@ -286,8 +291,8 @@ fn next_back(&mut self) -> Option<(A::Item, B::Item)>
     #[inline]
     unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item {
         // SAFETY: the caller must uphold the contract for
-        // `Iterator::get_unchecked`.
-        unsafe { (self.a.get_unchecked(idx), self.b.get_unchecked(idx)) }
+        // `Iterator::__iterator_get_unchecked`.
+        unsafe { (self.a.__iterator_get_unchecked(idx), self.b.__iterator_get_unchecked(idx)) }
     }
 }
 
@@ -386,8 +391,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 ///
 /// `size` may not be overridden.
 ///
-/// `<Self as Iterator>::get_unchecked` must be safe to call provided the
-/// following conditions are met.
+/// `<Self as Iterator>::__iterator_get_unchecked` must be safe to call
+/// provided the following conditions are met.
 ///
 /// 1. `0 <= idx` and `idx < self.size()`.
 /// 2. If `self: !Clone`, then `get_unchecked` is never called with the same
@@ -399,7 +404,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 ///     * `std::clone::Clone::clone`
 ///     * `std::iter::Iterator::size_hint()`
 ///     * `std::iter::Iterator::next_back()`
-///     * `std::iter::Iterator::get_unchecked()`
+///     * `std::iter::Iterator::__iterator_get_unchecked()`
 ///     * `std::iter::TrustedRandomAccess::size()`
 ///
 /// Further, given that these conditions are met, it must guarantee that:
@@ -424,7 +429,7 @@ fn size(&self) -> usize
     fn may_have_side_effect() -> bool;
 }
 
-/// Like `Iterator::get_unchecked`, but doesn't require the compiler to
+/// Like `Iterator::__iterator_get_unchecked`, but doesn't require the compiler to
 /// know that `U: TrustedRandomAccess`.
 ///
 /// ## Safety
@@ -436,13 +441,13 @@ pub(in crate::iter::adapters) unsafe fn try_get_unchecked<I>(it: &mut I, idx: us
     I: Iterator,
 {
     // SAFETY: the caller must uphold the contract for
-    // `Iterator::get_unchecked`.
+    // `Iterator::__iterator_get_unchecked`.
     unsafe { it.try_get_unchecked(idx) }
 }
 
 unsafe trait SpecTrustedRandomAccess: Iterator {
     /// If `Self: TrustedRandomAccess`, it must be safe to call a
-    /// `Iterator::get_unchecked(self, index)`.
+    /// `Iterator::__iterator_get_unchecked(self, index)`.
     unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item;
 }
 
@@ -455,7 +460,7 @@ unsafe impl<I: Iterator> SpecTrustedRandomAccess for I {
 unsafe impl<I: Iterator + TrustedRandomAccess> SpecTrustedRandomAccess for I {
     unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item {
         // SAFETY: the caller must uphold the contract for
-        // `Iterator::get_unchecked`.
-        unsafe { self.get_unchecked(index) }
+        // `Iterator::__iterator_get_unchecked`.
+        unsafe { self.__iterator_get_unchecked(index) }
     }
 }