Can I do this in one expression?
*map.entry(key).or_default() += 1;
let count = *map.get(&key).unwrap();
Ideally, I would like this to be an atomic operation, but I can lock if needed.
You can:
let count = *map.entry(key).and_modify(|v| *v += 1).or_insert(1);
This will: