Check before unwrapping in stats (#717)

Should fix the error @pdecat found!
This commit is contained in:
Ellie Huxtable 2023-02-14 09:45:55 +00:00 committed by GitHub
parent 5cb43772dc
commit 1f7d3a34e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,9 +26,13 @@ pub struct Cmd {
fn compute_stats(history: &[History], count: usize) -> Result<()> { fn compute_stats(history: &[History], count: usize) -> Result<()> {
let mut commands = HashMap::<&str, usize>::new(); let mut commands = HashMap::<&str, usize>::new();
for i in history { for i in history {
*commands let command = i.command.split_ascii_whitespace().next();
.entry(i.command.split_ascii_whitespace().next().unwrap())
.or_default() += 1; if command.is_none() {
continue;
}
*commands.entry(command.unwrap()).or_default() += 1;
} }
let unique = commands.len(); let unique = commands.len();
let mut top = commands.into_iter().collect::<Vec<_>>(); let mut top = commands.into_iter().collect::<Vec<_>>();