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 @@ fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
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 @@ fn advance(&mut self, f: &fn(A) -> bool) -> bool {
}
}
}
#[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> {