1- use crate :: author:: Author ;
1+ use crate :: { author:: Author , curse :: Curse } ;
22use hashbrown:: HashMap ;
33use std:: fmt;
44
@@ -12,7 +12,7 @@ pub struct Repo {
1212 /// Count of the total amount of curses used in the commits.
1313 pub total_curses : usize ,
1414 /// HashMap of all the naughty words used by the authors.
15- pub curses : HashMap < String , usize > ,
15+ pub curses : HashMap < String , Curse > ,
1616 /// HashMap of all the authors that have been committed.
1717 pub authors : HashMap < String , Author > ,
1818}
@@ -21,8 +21,11 @@ impl fmt::Display for Repo {
2121 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2222 write ! (
2323 f,
24- "{}: ({}/{}) naughty commits/commits\n {:#?}" ,
25- self . name, self . total_curses, self . total_commits, self . curses
24+ "{}: ({}/{}) naughty commits/commits:\n {}" ,
25+ self . name,
26+ self . total_curses,
27+ self . total_commits,
28+ Curse :: sort( & self . curses)
2629 )
2730 }
2831}
@@ -54,11 +57,11 @@ impl Repo {
5457 /// Counts all the naughty words used by authors.
5558 pub fn count_curses ( & mut self ) {
5659 for author in self . authors . values ( ) {
57- for ( curse , count ) in & author. curses {
60+ for ( name , curse ) in & author. curses {
5861 self . curses
59- . entry ( curse . to_string ( ) )
60- . and_modify ( |c| * c += count)
61- . or_insert ( * count) ;
62+ . entry ( name . to_string ( ) )
63+ . and_modify ( |c| c . count += curse . count )
64+ . or_insert ( Curse :: new ( name . as_str ( ) , curse . count ) ) ;
6265 }
6366 }
6467 }
0 commit comments