Skip to content

Commit

Permalink
fix panic in lang mode when folder was empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Orciument committed Apr 14, 2024
1 parent dd1dda0 commit 4831141
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/grafzahl/count_modes/custom_modes/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::AppState;
use crate::grafzahl::count_modes::countable::Countable;
use crate::grafzahl::language::languages::get_lang;

#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub(crate) struct LanguageCount(HashMap<String, u32>);

impl Add for LanguageCount {
Expand All @@ -30,9 +30,13 @@ impl Sum for LanguageCount {
impl Display for LanguageCount {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.0.len() > 1 { return write!(f, ""); }
let lang_name = self.0.keys().next().unwrap();
let amount = self.0.values().next().unwrap();
write!(f, "{}: {}", amount, lang_name)
let lang_name = self.0.keys().next();
let amount = self.0.values().next();
if lang_name.is_some() || amount.is_some() {
write!(f, "{}: {}", amount.unwrap(), lang_name.unwrap())
} else {
write!(f, "0")
}
}
}

Expand Down

0 comments on commit 4831141

Please sign in to comment.