Move TrustedRandomAccess into Zip module

This commit is contained in:
Clar Fon 2018-12-19 16:33:53 -05:00
parent 3c44e1f085
commit 520e8b001e
6 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,5 @@
use cmp;
use fmt;
use iter_private::TrustedRandomAccess;
use ops::Try;
use usize;
use intrinsics;
@ -11,6 +10,7 @@ mod zip;
pub use self::zip::Zip;
pub(super) use self::zip::ZipImpl;
pub(crate) use self::zip::TrustedRandomAccess;
/// A double-ended iterator with the direction inverted.
///

View File

@ -1,5 +1,4 @@
use cmp;
use iter_private::TrustedRandomAccess;
use super::super::{Iterator, DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen};
/// An iterator that iterates two other iterators simultaneously.
@ -259,3 +258,20 @@ impl<A, B> FusedIterator for Zip<A, B>
unsafe impl<A, B> TrustedLen for Zip<A, B>
where A: TrustedLen, B: TrustedLen,
{}
/// An iterator whose items are random-accessible efficiently
///
/// # Safety
///
/// The iterator's .len() and size_hint() must be exact.
/// `.len()` must be cheap to call.
///
/// .get_unchecked() must return distinct mutable references for distinct
/// indices (if applicable), and must return a valid reference if index is in
/// 0..self.len().
pub(crate) unsafe trait TrustedRandomAccess : ExactSizeIterator {
unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item;
/// Returns `true` if getting an iterator element may have
/// side effects. Remember to take inner iterators into account.
fn may_have_side_effect() -> bool;
}

View File

@ -354,6 +354,7 @@ pub use self::adapters::Flatten;
pub use self::adapters::Copied;
use self::adapters::{flatten_compat, ChainState, ZipImpl};
pub(crate) use self::adapters::TrustedRandomAccess;
mod range;
mod sources;

View File

@ -219,7 +219,6 @@ pub mod task;
pub mod alloc;
// note: does not need to be public
mod iter_private;
mod tuple;
mod unit;

View File

@ -34,7 +34,6 @@ use result::Result::{Ok, Err};
use ptr;
use mem;
use marker::{Copy, Send, Sync, Sized, self};
use iter_private::TrustedRandomAccess;
#[unstable(feature = "slice_internals", issue = "0",
reason = "exposed from core to be reused in std; use the memchr crate")]

View File

@ -9,8 +9,7 @@ use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
use char;
use fmt;
use iter::{Map, Cloned, FusedIterator, TrustedLen, Filter};
use iter_private::TrustedRandomAccess;
use iter::{Map, Cloned, FusedIterator, TrustedLen, TrustedRandomAccess, Filter};
use slice::{self, SliceIndex, Split as SliceSplit};
use mem;