about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-08-08 20:33:28 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-08-10 07:01:08 -0700
commita6614621afbbcc04c503a4828adbb0acc4e0fe20 (patch)
treeb2106f009bf9bef6f62ab33349457cfd9a539c35 /src/libstd
parent229eeda4cd3f8013538edfa0c82f6779555012f6 (diff)
downloadrust-a6614621afbbcc04c503a4828adbb0acc4e0fe20.tar.gz
rust-a6614621afbbcc04c503a4828adbb0acc4e0fe20.zip
std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtil
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/iterator.rs39
-rw-r--r--src/libstd/prelude.rs2
-rw-r--r--src/libstd/str.rs2
3 files changed, 15 insertions, 28 deletions
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index d10a5541e41..3e0f9344600 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -55,32 +55,7 @@ pub trait Iterator<A> {
 pub trait DoubleEndedIterator<A>: Iterator<A> {
     /// Yield an element from the end of the range, returning `None` if the range is empty.
     fn next_back(&mut self) -> Option<A>;
-}
-
-/// An object implementing random access indexing by `uint`
-///
-/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
-pub trait RandomAccessIterator<A>: Iterator<A> {
-    /// Return the number of indexable elements. At most `std::uint::max_value`
-    /// elements are indexable, even if the iterator represents a longer range.
-    fn indexable(&self) -> uint;
-
-    /// Return an element at an index
-    fn idx(&self, index: uint) -> Option<A>;
-}
-
-/// Iterator adaptors provided for every `DoubleEndedIterator` implementation.
-///
-/// In the future these will be default methods instead of a utility trait.
-pub trait DoubleEndedIteratorUtil {
-    /// Flip the direction of the iterator
-    fn invert(self) -> Invert<Self>;
-}
 
-/// Iterator adaptors provided for every `DoubleEndedIterator` implementation.
-///
-/// In the future these will be default methods instead of a utility trait.
-impl<A, T: DoubleEndedIterator<A>> DoubleEndedIteratorUtil for T {
     /// Flip the direction of the iterator
     ///
     /// The inverted iterator flips the ends on an iterator that can already
@@ -94,11 +69,23 @@ impl<A, T: DoubleEndedIterator<A>> DoubleEndedIteratorUtil for T {
     /// Note: Random access with inverted indices still only applies to the first
     /// `uint::max_value` elements of the original iterator.
     #[inline]
-    fn invert(self) -> Invert<T> {
+    fn invert(self) -> Invert<Self> {
         Invert{iter: self}
     }
 }
 
+/// An object implementing random access indexing by `uint`
+///
+/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
+pub trait RandomAccessIterator<A>: Iterator<A> {
+    /// Return the number of indexable elements. At most `std::uint::max_value`
+    /// elements are indexable, even if the iterator represents a longer range.
+    fn indexable(&self) -> uint;
+
+    /// Return an element at an index
+    fn idx(&self, index: uint) -> Option<A>;
+}
+
 /// An double-ended iterator with the direction inverted
 #[deriving(Clone)]
 pub struct Invert<T> {
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index f035e61fa1e..c560f9ed930 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -51,7 +51,7 @@ pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 pub use hash::Hash;
 pub use iter::Times;
 pub use iterator::Extendable;
-pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil};
+pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator};
 pub use iterator::{ClonableIterator, OrdIterator};
 pub use num::{Num, NumCast};
 pub use num::{Orderable, Signed, Unsigned, Round};
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index b72e5a87c6d..539c6e38a99 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -25,7 +25,7 @@ use container::{Container, Mutable};
 use iter::Times;
 use iterator::{Iterator, FromIterator, Extendable, IteratorUtil};
 use iterator::{Filter, AdditiveIterator, Map};
-use iterator::{Invert, DoubleEndedIterator, DoubleEndedIteratorUtil};
+use iterator::{Invert, DoubleEndedIterator};
 use libc;
 use num::Zero;
 use option::{None, Option, Some};