Skip to content

Commit

Permalink
Move TrustedRandomAccess into Zip module
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Jan 22, 2019
1 parent 3c44e1f commit 520e8b0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cmp;
use fmt;
use iter_private::TrustedRandomAccess;
use ops::Try;
use usize;
use intrinsics;
Expand All @@ -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.
///
Expand Down
18 changes: 17 additions & 1 deletion src/libcore/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ pub mod task;
pub mod alloc;

// note: does not need to be public
mod iter_private;
mod tuple;
mod unit;

Expand Down
1 change: 0 additions & 1 deletion src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 520e8b0

Please sign in to comment.