libcore: Add IteratorUtil::to_vec() method

This commit is contained in:
gifnksm 2013-05-17 22:54:32 +09:00
parent dbbc244f73
commit f7e58ebe84

View File

@ -45,6 +45,7 @@ pub trait IteratorUtil<A> {
fn advance(&mut self, f: &fn(A) -> bool);
#[cfg(not(stage0))]
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
fn to_vec(self) -> ~[A];
}
/// 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 {
}
}
}
#[inline(always)]
fn to_vec(self) -> ~[A] {
let mut v = ~[];
let mut it = self;
for it.advance() |x| { v.push(x); }
return v;
}
}
pub struct ChainIterator<T, U> {