I have a function that returns a HashMap<String, u64>
and I want to extend another HashMap<String, u64>
with the return value of that function:
pub fn find_album(&self, artist: String, album: String) -> Vec<String>
pub fn get_tracks(&self, album_id: String) -> HashMap<String, u64>
let mut track_nums: HashMap<String, u64> = HashMap::new();
for id in client.find_album(artist, album) {
track_nums.extend(client.get_tracks(id).iter());
}
This gives me an error:
error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, std::string::String, u64> as std::iter::IntoIterator>::Item == (std::string::String, u64)`
--> src/main.rs:23:20
|
23 | track_nums.extend(client.get_tracks(id).iter());
| ^^^^^^ expected reference, found struct `std::string::String`
|
= note: expected type `(&std::string::String, &u64)`
found type `(std::string::String, u64)`
What's the correct way to extend a HashMap
with all of the (key, value)
pairs from another HashMap
?