FromIterator

FromIterator lets you build a collection from an Iterator.

  1. fn main() {
  2. let primes = vec![2, 3, 5, 7];
  3. let prime_squares = primes
  4. .into_iter()
  5. .map(|prime| prime * prime)
  6. .collect::<Vec<_>>();
  7. }

Iterator implements fn collect<B>(self) -> B where B: FromIterator<Self::Item>, Self: Sized

There are also implementations which let you do cool things like convert an Iterator<Item = Result<V, E>> into a Result<Vec<V>, E>.