about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMarvin Löbel <loebel.marvin@gmail.com>2013-06-06 22:34:50 +0200
committerMarvin Löbel <loebel.marvin@gmail.com>2013-06-06 22:40:35 +0200
commitcac489115458af3eed301d8d4f9c6c7d6779b058 (patch)
tree829ac746ec1726fb7acd900ad2cd9768713a6d8c /src/libstd
parent070015468d014f93da2a366f7f5e37c0678f6c5b (diff)
downloadrust-cac489115458af3eed301d8d4f9c6c7d6779b058.tar.gz
rust-cac489115458af3eed301d8d4f9c6c7d6779b058.zip
Fixups
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/iter.rs12
-rw-r--r--src/libstd/iterator.rs15
-rw-r--r--src/libstd/prelude.rs5
-rw-r--r--src/libstd/vec.rs10
4 files changed, 23 insertions, 19 deletions
diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs
index 9a50b8a6741..8a0ec3ade4d 100644
--- a/src/libstd/iter.rs
+++ b/src/libstd/iter.rs
@@ -65,16 +65,6 @@ pub trait FromIter<T> {
     pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> Self;
 }
 
-// NOTE: This should be in vec but can't because of coherence
-impl<T> FromIter<T> for ~[T]{
-    #[inline(always)]
-    pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
-        let mut v = ~[];
-        for iter |x| { v.push(x) }
-        v
-    }
-}
-
 /**
  * Return true if `predicate` is true for any values yielded by an internal iterator.
  *
@@ -269,7 +259,7 @@ mod tests {
 
     #[test]
     fn test_from_iter() {
-        let xs: = ~[1, 2, 3];
+        let xs = ~[1, 2, 3];
         let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) };
         assert_eq!(xs, ys);
     }
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index 2a3bbc3322d..7f723e44c2b 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -19,9 +19,12 @@ implementing the `Iterator` trait.
 
 use cmp;
 use iter;
-use iter::FromIter;
+use iter::{FromIter, Times};
 use num::{Zero, One};
-use prelude::*;
+use option::{Option, Some, None};
+use ops::{Add, Mul};
+use cmp::Ord;
+use clone::Clone;
 
 /// An interface for dealing with "external iterators". These types of iterators
 /// can be resumed at any time as all state is stored internally as opposed to
@@ -871,9 +874,9 @@ mod tests {
     use uint;
 
     #[test]
-    fn test_counter_to_vec() {
+    fn test_counter_from_iter() {
         let mut it = Counter::new(0, 5).take(10);
-        let xs = iter::to_vec(|f| it.advance(f));
+        let xs: ~[int] = iter::FromIter::from_iter::<int, ~[int]>(|f| it.advance(f));
         assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
     }
 
@@ -904,7 +907,7 @@ mod tests {
     fn test_filter_map() {
         let mut it = Counter::new(0u, 1u).take(10)
             .filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
-        assert_eq!(it.to_vec(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
+        assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
     }
 
     #[test]
@@ -1065,7 +1068,7 @@ mod tests {
 
     #[test]
     fn test_collect() {
-        let a = [1, 2, 3, 4, 5];
+        let a = ~[1, 2, 3, 4, 5];
         let b: ~[int] = a.iter().transform(|&x| x).collect();
         assert_eq!(a, b);
     }
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index ab8a699a502..bb10cec30ed 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -14,7 +14,7 @@ Many programming languages have a 'prelude': a particular subset of the
 libraries that come with the language. Every program imports the prelude by
 default.
 
-For example, it would be annoying to add `use io::println;` to every single
+For example, it would be annoying to add `use std::io::println;` to every single
 program, and the vast majority of Rust programs will wish to print to standard
 output. Therefore, it makes sense to import it into every program.
 
@@ -49,7 +49,8 @@ pub use hash::Hash;
 pub use old_iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
 pub use old_iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
 pub use old_iter::{ExtendedMutableIter};
-pub use iter::Times;
+pub use iter::{Times, FromIter};
+// FIXME: #5898 pub use iterator::{Iterator, IteratorUtil};
 pub use num::{Num, NumCast};
 pub use num::{Orderable, Signed, Unsigned, Round};
 pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic};
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 80905bdaeab..8340b956b65 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -20,6 +20,7 @@ use clone::Clone;
 use old_iter::BaseIter;
 use old_iter;
 use iterator::Iterator;
+use iter::FromIter;
 use kinds::Copy;
 use libc;
 use old_iter::CopyableIter;
@@ -2996,6 +2997,15 @@ impl<'self, T> Iterator<&'self mut T> for MutVecIterator<'self, T> {
     }
 }
 
+impl<T> FromIter<T> for ~[T]{
+    #[inline(always)]
+    pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
+        let mut v = ~[];
+        for iter |x| { v.push(x) }
+        v
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use option::{None, Option, Some};