fork download
  1. fn main() {
  2. let mut c = std::collections::HashMap::new();
  3. for &i in &vec![3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] {
  4. *(c.entry(i).or_insert(0)) += 1;
  5. }
  6. println!("c = {:?}", c);
  7. let num_of_five = *c.get(&5).unwrap_or(&0);
  8. println!("num_of_five = {}", num_of_five);
  9. *(c.entry(3).or_insert(0)) += 57;
  10. println!("c = {:?}", c);
  11. }
  12.  
Success #stdin #stdout 0s 4536KB
stdin
Standard input is empty
stdout
c = {3: 2, 6: 1, 4: 1, 9: 1, 1: 2, 2: 1, 5: 3}
num_of_five = 3
c = {3: 59, 6: 1, 4: 1, 9: 1, 1: 2, 2: 1, 5: 3}