Reputation: 24642
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?
Upvotes: 2
Views: 2231
Reputation: 16660
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)]
Upvotes: 1
Reputation: 90852
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()
.
Upvotes: 3