I can not find a way to collect the values of a HashMap
into a Vec
in the documentation. I have score_table: HashMap
If you don't need score_table
anymore, you can transfer the ownership of Score
values to all_scores
by:
let all_scores: Vec = score_table.into_iter()
.map(|(_id, score)| score)
.collect();
This approach will be faster and consume less memory than the clone approach by @apetranzilla. It also supports any struct, not only structs that implement Clone
.