2

The docs seem to indicate that after zipping two iterators together, you can turn them into an array with .from_iterator(), but when I try to do this, rust reports:

std::iter::Zip<std::vec::VecIterator<,int>,std::vec::VecIterator<,int>>` does not implement any method in scope named `from_iterator`

Could someone please give working sample code for rust 0.8 that turns a Zip into an array?

rene
  • 41,474
  • 78
  • 114
  • 152
mcandre
  • 22,868
  • 20
  • 88
  • 147

2 Answers2

3

That would be FromIterator::from_iterator(iterator).

The more commonly used interface for that is Iterator.collect (link is to master docs, but it's the same in 0.8 and 0.9), whereby you will call iterator.collect().

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
1

Rust 0.8 is dated, you should upgrade to 0.9. The following works in 0.9:

let a = ~[1,12,3,67];
let b = ~[56,74,13,2];
let c: ~[(&int,&int)] = a.iter().zip(b.iter()).collect();
println!("{:?}", c);

Result:

~[(&1, &56), (&12, &74), (&3, &13), (&67, &2)]
A.B.
  • 15,364
  • 3
  • 61
  • 64
  • I would, but Homebrew doesn't have a formula for installing 0.9 yet. – mcandre Jan 14 '14 at 16:59
  • @mcandre: I believe you can specify `--HEAD` and it'll install master—that's where the action is and I would strongly recommend that you use that rather than 0.8 or 0.9. – Chris Morgan Jan 14 '14 at 23:30