fn main() {
let x = &vec![1,2,3,5,7,11,13,17,19,23,29,31,37,41,47];
let mut i = x.iter().map(|x|{2*x});
while let Some(value) = i.next() {
println!("{}", value);
}
}
Why does this work?
If I change let mut i = into let i =, I get the error:
|
3 | let i = x.iter().map(|x|{2*x});
| - help: consider changing this to be mutable: `mut i`
4 |
5 | while let Some(value) = i.next() {
| ^^^^^^^^ cannot borrow as mutable
Questions:
- Do I really need to borrow as mutable? (Maybe I am missing something here.)
- Why do I need to borrow as mutable?
- What is really being mutable here? Is it
i(the iterable) orvalue(its values)?