mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
Add a to_owned_vec method to IteratorUtil.
This commit is contained in:
@@ -333,6 +333,18 @@ fn flat_map_<'r, B, U: Iterator<B>>(self, f: &'r fn(A) -> U)
|
||||
/// ~~~
|
||||
fn collect<B: FromIterator<A, Self>>(&mut self) -> B;
|
||||
|
||||
/// Loops through the entire iterator, collecting all of the elements into
|
||||
/// a unique vector. This is simply collect() specialized for vectors.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ~~~ {.rust}
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let b: ~[int] = a.iter().transform(|&x| x).to_owned_vec();
|
||||
/// assert!(a == b);
|
||||
/// ~~~
|
||||
fn to_owned_vec(&mut self) -> ~[A];
|
||||
|
||||
/// Loops through `n` iterations, returning the `n`th element of the
|
||||
/// iterator.
|
||||
///
|
||||
@@ -529,6 +541,11 @@ fn collect<B: FromIterator<A, T>>(&mut self) -> B {
|
||||
FromIterator::from_iterator(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_owned_vec(&mut self) -> ~[A] {
|
||||
self.collect()
|
||||
}
|
||||
|
||||
/// Return the `n`th item yielded by an iterator.
|
||||
#[inline]
|
||||
fn nth(&mut self, mut n: uint) -> Option<A> {
|
||||
|
||||
Reference in New Issue
Block a user