Hi, I am new to Rust (yet another), and have some trouble with iterators and collect()
semantics :
I am trying to iterate over a Vect of Pairs of isize, and transform it in a Vect of Pairs of Pairs of isize and f32 (link to a playground with this code) :
type Point = (isize, isize); // (x,y)
fn work_on_tuples(tuples: &Vec<Point>){
let moves : (&Point, f32) = tuples.iter()
.map(|x : &Point| (x, 1.1 as f32))
.collect();
}
Gives me the following compilation error :
error[E0277]: the trait bound `(&(isize, isize), f32): std::iter::FromIterator<(&(isize, isize), f32)>` is not satisfied
--> src/main.rs:64:14
|
64 | .collect();
| ^^^^^^^ a collection of type `(&(isize, isize), f32)` cannot be built from an iterator over elements of type `(&(isize, isize), f32)`
|
= help: the trait `std::iter::FromIterator<(&(isize, isize), f32)>` is not implemented for `(&(isize, isize), f32)`
So here are the points I do not understand :
-
I do not understand this message :
(&(isize, isize), f32)` cannot be built from an iterator over elements of type `(&(isize, isize), f32)
: creating an X collection from an X iterator seems ok to me ? -
I do not understand why would there be a problem creating a vector of tuples containing tuples references and float ?
Thank you for your help fellow rustaceans.