diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-08-08 20:33:28 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-08-10 07:01:08 -0700 |
| commit | a6614621afbbcc04c503a4828adbb0acc4e0fe20 (patch) | |
| tree | b2106f009bf9bef6f62ab33349457cfd9a539c35 /src/libstd/iterator.rs | |
| parent | 229eeda4cd3f8013538edfa0c82f6779555012f6 (diff) | |
| download | rust-a6614621afbbcc04c503a4828adbb0acc4e0fe20.tar.gz rust-a6614621afbbcc04c503a4828adbb0acc4e0fe20.zip | |
std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtil
Diffstat (limited to 'src/libstd/iterator.rs')
| -rw-r--r-- | src/libstd/iterator.rs | 39 |
1 files changed, 13 insertions, 26 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> { |
