about summary refs log tree commit diff
path: root/src/libstd/iterator.rs
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-06-21 07:57:22 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-06-22 15:59:59 -0400
commitc9342663df3e705f6fe380f3d4f46c4a7be8035e (patch)
tree9cc269199bfdf767495e7d2dec17ed9b8230c674 /src/libstd/iterator.rs
parent468cbd9d014d4f8610694057f1a8132f1eaf0b19 (diff)
downloadrust-c9342663df3e705f6fe380f3d4f46c4a7be8035e.tar.gz
rust-c9342663df3e705f6fe380f3d4f46c4a7be8035e.zip
iterator: add a FromIterator trait
This is able to take advantage of the lower bound from the size hint.
Diffstat (limited to 'src/libstd/iterator.rs')
-rw-r--r--src/libstd/iterator.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index fa27f4560c1..46e05935594 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -27,6 +27,12 @@ use ops::{Add, Mul};
 use cmp::Ord;
 use clone::Clone;
 
+/// Conversion from an `Iterator`
+pub trait FromIterator<A, T: Iterator<A>> {
+    /// Build a container with elements from an external iterator.
+    pub fn from_iterator(iterator: &mut T) -> Self;
+}
+
 /// 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
 /// being located on the call stack.
@@ -931,7 +937,7 @@ mod tests {
     #[test]
     fn test_counter_from_iter() {
         let mut it = Counter::new(0, 5).take_(10);
-        let xs: ~[int] = iter::FromIter::from_iter::<int, ~[int]>(|f| it.advance(f));
+        let xs: ~[int] = FromIterator::from_iterator(&mut it);
         assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
     }