Created
April 23, 2020 12:11
-
-
Save saidaspen/1d4e39551eac7c8da2e691d162026249 to your computer and use it in GitHub Desktop.
Nested hashmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut scores: HashMap<String, HashMap<String, u32>> = HashMap::new(); | |
1 for repo in tracked_repos { | |
2 let contributions: Vec<Contribution> = gh | |
3 .get_contributors(&repo) | |
4 .expect("unable to get contributors for repo") | |
5 .iter() | |
6 .filter(|c| participants_set.contains(&c.login)) | |
7 .cloned() | |
8 .collect(); | |
9 for contrib in contributions { | |
10 let login = contrib.login.to_string(); | |
11 scores | |
12 .entry(login.clone()) | |
13 .and_modify(|nested| { | |
14 nested.insert(repo.clone(), contrib.contributions); | |
15 }) | |
16 .or_insert_with(|| { | |
17 let mut new_map: HashMap<String, u32> = HashMap::new(); | |
18 new_map.insert(repo.clone(), contrib.contributions); | |
19 new_map | |
20 }); | |
21 } | |
22 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment