Skip to content

Commit f7e58eb

Browse files
committed
libcore: Add IteratorUtil::to_vec() method
1 parent dbbc244 commit f7e58eb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libcore/iterator.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub trait IteratorUtil<A> {
4545
fn advance(&mut self, f: &fn(A) -> bool);
4646
#[cfg(not(stage0))]
4747
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
48+
fn to_vec(self) -> ~[A];
4849
}
4950

5051
/// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also
@@ -131,6 +132,14 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
131132
}
132133
}
133134
}
135+
136+
#[inline(always)]
137+
fn to_vec(self) -> ~[A] {
138+
let mut v = ~[];
139+
let mut it = self;
140+
for it.advance() |x| { v.push(x); }
141+
return v;
142+
}
134143
}
135144

136145
pub struct ChainIterator<T, U> {

0 commit comments

Comments
 (0)