Skip to content

Commit af8b7c3

Browse files
committed
---
yaml --- r: 63567 b: refs/heads/snap-stage3 c: c934266 h: refs/heads/master i: 63565: 6e098a9 63563: f0d45c2 63559: 3783355 63551: 4cf0159 v: v3
1 parent 2b2cf63 commit af8b7c3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 468cbd9d014d4f8610694057f1a8132f1eaf0b19
4+
refs/heads/snap-stage3: c9342663df3e705f6fe380f3d4f46c4a7be8035e
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ use ops::{Add, Mul};
2727
use cmp::Ord;
2828
use clone::Clone;
2929

30+
/// Conversion from an `Iterator`
31+
pub trait FromIterator<A, T: Iterator<A>> {
32+
/// Build a container with elements from an external iterator.
33+
pub fn from_iterator(iterator: &mut T) -> Self;
34+
}
35+
3036
/// An interface for dealing with "external iterators". These types of iterators
3137
/// can be resumed at any time as all state is stored internally as opposed to
3238
/// being located on the call stack.
@@ -931,7 +937,7 @@ mod tests {
931937
#[test]
932938
fn test_counter_from_iter() {
933939
let mut it = Counter::new(0, 5).take_(10);
934-
let xs: ~[int] = iter::FromIter::from_iter::<int, ~[int]>(|f| it.advance(f));
940+
let xs: ~[int] = FromIterator::from_iterator(&mut it);
935941
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
936942
}
937943

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
1919
use clone::Clone;
2020
use old_iter::BaseIter;
2121
use old_iter;
22-
use iterator::{Iterator, IteratorUtil};
22+
use iterator::{FromIterator, Iterator, IteratorUtil};
2323
use iter::FromIter;
2424
use kinds::Copy;
2525
use libc;
@@ -2511,6 +2511,18 @@ impl<T> FromIter<T> for ~[T]{
25112511
}
25122512
}
25132513

2514+
#[cfg(not(stage0))]
2515+
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
2516+
pub fn from_iterator(iterator: &mut T) -> ~[A] {
2517+
let (lower, _) = iterator.size_hint();
2518+
let mut xs = with_capacity(lower.get_or_zero());
2519+
for iterator.advance |x| {
2520+
xs.push(x);
2521+
}
2522+
xs
2523+
}
2524+
}
2525+
25142526
#[cfg(test)]
25152527
mod tests {
25162528
use option::{None, Option, Some};

0 commit comments

Comments
 (0)