When iterating a list of tuples, the &
is needed to make it work. Thus this will work ...
for &(a, b, c) in [("hello", 1.0, 5), ("world", 2.0, 2)].iter() {
println!("{} {} {}", a, b, c);
}
but that won't ...
for (a, b, c) in [("hello", 1.0, 5), ("world", 2.0, 2)].iter() {
println!("{} {} {}", a, b, c);
}
// type mismatch resolving `<core::slice::Iter<'_, (&str, _, _)> as core::iter::Iterator>::Item == (_, _, _)`:
// expected &-ptr,
found tuple [E0271]
I am sure it has to do with intricacies of the destructuring syntax that I have not yet fully internalised.
Can you explain which syntactical truth is behind the ampersand ?