Closed
Description
This code:
use std::collections::HashMap;
fn encode2(vals: &[u32], encoding: &HashMap<u32, String>) -> String {
vals.iter().map(|k| encoding[k]).collect()
}
fn main() {}
It doesn't compile:
error[E0507]: cannot move out of indexed content
--> ...\test.rs:3:25
|
3 | vals.iter().map(|k| encoding[k]).collect()
| ^^^^^^^^^^^ cannot move out of indexed content
error: aborting due to previous error
Perhaps the compiler could suggest the programmer to add a &* :
vals.iter().map(|k| &*encoding[k]).collect()
Metadata
Metadata
Assignees
Labels
No labels