Skip to content

Instantly share code, notes, and snippets.

@saidaspen
Created April 23, 2020 12:11
Show Gist options
  • Save saidaspen/1d4e39551eac7c8da2e691d162026249 to your computer and use it in GitHub Desktop.
Save saidaspen/1d4e39551eac7c8da2e691d162026249 to your computer and use it in GitHub Desktop.
Nested hashmap
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