Skip to content

Commit 520e8b0

Browse files
author
Clar Fon
committed
Move TrustedRandomAccess into Zip module
1 parent 3c44e1f commit 520e8b0

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

src/libcore/iter/adapters/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use cmp;
22
use fmt;
3-
use iter_private::TrustedRandomAccess;
43
use ops::Try;
54
use usize;
65
use intrinsics;
@@ -11,6 +10,7 @@ mod zip;
1110

1211
pub use self::zip::Zip;
1312
pub(super) use self::zip::ZipImpl;
13+
pub(crate) use self::zip::TrustedRandomAccess;
1414

1515
/// A double-ended iterator with the direction inverted.
1616
///

src/libcore/iter/adapters/zip.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use cmp;
2-
use iter_private::TrustedRandomAccess;
32
use super::super::{Iterator, DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen};
43

54
/// An iterator that iterates two other iterators simultaneously.
@@ -259,3 +258,20 @@ impl<A, B> FusedIterator for Zip<A, B>
259258
unsafe impl<A, B> TrustedLen for Zip<A, B>
260259
where A: TrustedLen, B: TrustedLen,
261260
{}
261+
262+
/// An iterator whose items are random-accessible efficiently
263+
///
264+
/// # Safety
265+
///
266+
/// The iterator's .len() and size_hint() must be exact.
267+
/// `.len()` must be cheap to call.
268+
///
269+
/// .get_unchecked() must return distinct mutable references for distinct
270+
/// indices (if applicable), and must return a valid reference if index is in
271+
/// 0..self.len().
272+
pub(crate) unsafe trait TrustedRandomAccess : ExactSizeIterator {
273+
unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item;
274+
/// Returns `true` if getting an iterator element may have
275+
/// side effects. Remember to take inner iterators into account.
276+
fn may_have_side_effect() -> bool;
277+
}

src/libcore/iter/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ pub use self::adapters::Flatten;
354354
pub use self::adapters::Copied;
355355

356356
use self::adapters::{flatten_compat, ChainState, ZipImpl};
357+
pub(crate) use self::adapters::TrustedRandomAccess;
357358

358359
mod range;
359360
mod sources;

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ pub mod task;
219219
pub mod alloc;
220220

221221
// note: does not need to be public
222-
mod iter_private;
223222
mod tuple;
224223
mod unit;
225224

src/libcore/slice/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use result::Result::{Ok, Err};
3434
use ptr;
3535
use mem;
3636
use marker::{Copy, Send, Sync, Sized, self};
37-
use iter_private::TrustedRandomAccess;
3837

3938
#[unstable(feature = "slice_internals", issue = "0",
4039
reason = "exposed from core to be reused in std; use the memchr crate")]

src/libcore/str/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
99

1010
use char;
1111
use fmt;
12-
use iter::{Map, Cloned, FusedIterator, TrustedLen, Filter};
13-
use iter_private::TrustedRandomAccess;
12+
use iter::{Map, Cloned, FusedIterator, TrustedLen, TrustedRandomAccess, Filter};
1413
use slice::{self, SliceIndex, Split as SliceSplit};
1514
use mem;
1615

0 commit comments

Comments
 (0)