about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-06-23 17:57:39 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-06-24 01:35:11 -0400
commite2e39234cc5509fb461b8805eeb32c5ce538ee6e (patch)
tree3d3e6047f22148cb76916b20c4ed274fc99a177d /src/libsyntax
parentac4211ef52a3577f901ed4dc7f370b05ca4e638d (diff)
downloadrust-e2e39234cc5509fb461b8805eeb32c5ce538ee6e.tar.gz
rust-e2e39234cc5509fb461b8805eeb32c5ce538ee6e.zip
remove old_iter
the `test/run-pass/class-trait-bounded-param.rs` test was xfailed and
written in an ancient dialect of Rust so I've just removed it

this also removes `to_vec` from DList because it's provided by
`std::iter::to_vec`

an Iterator implementation is added for OptVec but some transitional
internal iterator methods are still left
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/pipes/pipec.rs4
-rw-r--r--src/libsyntax/opt_vec.rs117
2 files changed, 40 insertions, 81 deletions
diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs
index a20528082ab..55ac9c5ec1c 100644
--- a/src/libsyntax/ext/pipes/pipec.rs
+++ b/src/libsyntax/ext/pipes/pipec.rs
@@ -375,7 +375,7 @@ impl gen_init for protocol {
         let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
         for (copy self.states).iter().advance |s| {
             for s.generics.ty_params.each |tp| {
-                match params.find(|tpp| tp.ident == tpp.ident) {
+                match params.iter().find_(|tpp| tp.ident == tpp.ident) {
                   None => params.push(*tp),
                   _ => ()
                 }
@@ -393,7 +393,7 @@ impl gen_init for protocol {
         let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
         let fields = do (copy self.states).iter().transform |s| {
             for s.generics.ty_params.each |tp| {
-                match params.find(|tpp| tp.ident == tpp.ident) {
+                match params.iter().find_(|tpp| tp.ident == tpp.ident) {
                   None => params.push(*tp),
                   _ => ()
                 }
diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs
index c537a3e8eba..8917b481dc7 100644
--- a/src/libsyntax/opt_vec.rs
+++ b/src/libsyntax/opt_vec.rs
@@ -17,9 +17,7 @@
  */
 
 use core::prelude::*;
-
-use core::old_iter;
-use core::old_iter::BaseIter;
+use core::vec::VecIterator;
 
 #[deriving(Encodable, Decodable)]
 pub enum OptVec<T> {
@@ -40,6 +38,13 @@ pub fn from<T>(t: ~[T]) -> OptVec<T> {
 }
 
 impl<T> OptVec<T> {
+    fn each(&self, blk: &fn(v: &T) -> bool) -> bool {
+        match *self {
+            Empty => true,
+            Vec(ref v) => v.iter().advance(blk)
+        }
+    }
+
     fn push(&mut self, t: T) {
         match *self {
             Vec(ref mut v) => {
@@ -78,6 +83,28 @@ impl<T> OptVec<T> {
             Vec(ref v) => v.len()
         }
     }
+
+    #[inline]
+    fn iter<'r>(&'r self) -> OptVecIterator<'r, T> {
+        match *self {
+            Empty => OptVecIterator{iter: None},
+            Vec(ref v) => OptVecIterator{iter: Some(v.iter())}
+        }
+    }
+
+    #[inline]
+    fn map_to_vec<B>(&self, op: &fn(&T) -> B) -> ~[B] {
+        self.iter().transform(op).collect()
+    }
+
+    fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
+        let mut index = 0;
+        self.map_to_vec(|a| {
+            let i = index;
+            index += 1;
+            op(i, a)
+        })
+    }
 }
 
 pub fn take_vec<T>(v: OptVec<T>) -> ~[T] {
@@ -96,22 +123,6 @@ impl<T:Copy> OptVec<T> {
         }
         return Vec(v0);
     }
-
-    fn push_all<I: BaseIter<T>>(&mut self, from: &I) {
-        for from.each |e| {
-            self.push(copy *e);
-        }
-    }
-
-    #[inline]
-    fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
-        let mut index = 0;
-        old_iter::map_to_vec(self, |a| {
-            let i = index;
-            index += 1;
-            op(i, a)
-        })
-    }
 }
 
 impl<A:Eq> Eq for OptVec<A> {
@@ -131,68 +142,16 @@ impl<A:Eq> Eq for OptVec<A> {
     }
 }
 
-impl<A> BaseIter<A> for OptVec<A> {
-    fn each(&self, blk: &fn(v: &A) -> bool) -> bool {
-        match *self {
-            Empty => true,
-            Vec(ref v) => v.iter().advance(blk)
-        }
-    }
-
-    fn size_hint(&self) -> Option<uint> {
-        Some(self.len())
-    }
+pub struct OptVecIterator<'self, T> {
+    priv iter: Option<VecIterator<'self, T>>
 }
 
-impl<A> old_iter::ExtendedIter<A> for OptVec<A> {
+impl<'self, T> Iterator<&'self T> for OptVecIterator<'self, T> {
     #[inline]
-    fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) -> bool {
-        old_iter::eachi(self, blk)
-    }
-    #[inline]
-    fn all(&self, blk: &fn(&A) -> bool) -> bool {
-        old_iter::all(self, blk)
-    }
-    #[inline]
-    fn any(&self, blk: &fn(&A) -> bool) -> bool {
-        old_iter::any(self, blk)
-    }
-    #[inline]
-    fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
-        old_iter::foldl(self, b0, blk)
-    }
-    #[inline]
-    fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
-        old_iter::position(self, f)
-    }
-    #[inline]
-    fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
-        old_iter::map_to_vec(self, op)
-    }
-    #[inline]
-    fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-        -> ~[B] {
-        old_iter::flat_map_to_vec(self, op)
-    }
-
-}
-
-impl<A: Eq> old_iter::EqIter<A> for OptVec<A> {
-    #[inline]
-    fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
-    #[inline]
-    fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
-}
-
-impl<A: Copy> old_iter::CopyableIter<A> for OptVec<A> {
-    #[inline]
-    fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
-        old_iter::filter_to_vec(self, pred)
-    }
-    #[inline]
-    fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
-    #[inline]
-    fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
-        old_iter::find(self, f)
+    fn next(&mut self) -> Option<&'self T> {
+        match self.iter {
+            Some(ref mut x) => x.next(),
+            None => None
+        }
     }
 }