Borrow checker Advanced
27 Double borrows
Two classics that look fine but borrow the same collection twice. The fixes are idioms you'll reuse constantly: the HashMap entry API, and collect-then-extend instead of mutating while iterating.
Fix echo_evens: collect the doubled evens first, then extend after the loop.
Hints
- Build the additions in a separate Vec first -- then nothing borrows
vwhen you push. let doubled: Vec<i32> = v.iter().filter(..).map(..).collect();thenv.extend(doubled);.
Reveal solution
fn echo_evens(v: &mut Vec<i32>) {
let doubled: Vec<i32> = v.iter().filter(|&&x| x % 2 == 0).map(|&x| x * 2).collect();
v.extend(doubled);
}