Skip to content

Commit a661462

Browse files
committed
std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtil
1 parent 229eeda commit a661462

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

src/libstd/iterator.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,7 @@ pub trait Iterator<A> {
5555
pub trait DoubleEndedIterator<A>: Iterator<A> {
5656
/// Yield an element from the end of the range, returning `None` if the range is empty.
5757
fn next_back(&mut self) -> Option<A>;
58-
}
59-
60-
/// An object implementing random access indexing by `uint`
61-
///
62-
/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
63-
pub trait RandomAccessIterator<A>: Iterator<A> {
64-
/// Return the number of indexable elements. At most `std::uint::max_value`
65-
/// elements are indexable, even if the iterator represents a longer range.
66-
fn indexable(&self) -> uint;
67-
68-
/// Return an element at an index
69-
fn idx(&self, index: uint) -> Option<A>;
70-
}
71-
72-
/// Iterator adaptors provided for every `DoubleEndedIterator` implementation.
73-
///
74-
/// In the future these will be default methods instead of a utility trait.
75-
pub trait DoubleEndedIteratorUtil {
76-
/// Flip the direction of the iterator
77-
fn invert(self) -> Invert<Self>;
78-
}
7958

80-
/// Iterator adaptors provided for every `DoubleEndedIterator` implementation.
81-
///
82-
/// In the future these will be default methods instead of a utility trait.
83-
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIteratorUtil for T {
8459
/// Flip the direction of the iterator
8560
///
8661
/// The inverted iterator flips the ends on an iterator that can already
@@ -94,11 +69,23 @@ impl<A, T: DoubleEndedIterator<A>> DoubleEndedIteratorUtil for T {
9469
/// Note: Random access with inverted indices still only applies to the first
9570
/// `uint::max_value` elements of the original iterator.
9671
#[inline]
97-
fn invert(self) -> Invert<T> {
72+
fn invert(self) -> Invert<Self> {
9873
Invert{iter: self}
9974
}
10075
}
10176

77+
/// An object implementing random access indexing by `uint`
78+
///
79+
/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
80+
pub trait RandomAccessIterator<A>: Iterator<A> {
81+
/// Return the number of indexable elements. At most `std::uint::max_value`
82+
/// elements are indexable, even if the iterator represents a longer range.
83+
fn indexable(&self) -> uint;
84+
85+
/// Return an element at an index
86+
fn idx(&self, index: uint) -> Option<A>;
87+
}
88+
10289
/// An double-ended iterator with the direction inverted
10390
#[deriving(Clone)]
10491
pub struct Invert<T> {

src/libstd/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
5151
pub use hash::Hash;
5252
pub use iter::Times;
5353
pub use iterator::Extendable;
54-
pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil};
54+
pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator};
5555
pub use iterator::{ClonableIterator, OrdIterator};
5656
pub use num::{Num, NumCast};
5757
pub use num::{Orderable, Signed, Unsigned, Round};

src/libstd/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use container::{Container, Mutable};
2525
use iter::Times;
2626
use iterator::{Iterator, FromIterator, Extendable, IteratorUtil};
2727
use iterator::{Filter, AdditiveIterator, Map};
28-
use iterator::{Invert, DoubleEndedIterator, DoubleEndedIteratorUtil};
28+
use iterator::{Invert, DoubleEndedIterator};
2929
use libc;
3030
use num::Zero;
3131
use option::{None, Option, Some};

0 commit comments

Comments
 (0)