-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enables us to sort the curses by occurrence and also fixes how the output looks at the same time by implementing Display. Fixes #3 and fixes #2.
- Loading branch information
Showing
4 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use hashbrown::HashMap; | ||
use std::fmt; | ||
|
||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] | ||
pub struct Curse { | ||
pub count: usize, | ||
pub curse: String, | ||
} | ||
|
||
impl fmt::Display for Curse { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "\t{}: {}", self.curse, self.count) | ||
} | ||
} | ||
|
||
impl Curse { | ||
pub fn new(curse: impl Into<String>, count: usize) -> Self { | ||
Curse { | ||
curse: curse.into(), | ||
count, | ||
} | ||
} | ||
|
||
pub fn sort(curses: &HashMap<String, Curse>) -> String { | ||
let mut curses: Vec<_> = curses.iter().map(|c| c.1).collect(); | ||
curses.sort_unstable(); | ||
curses.reverse(); | ||
let mut result = String::new(); | ||
for curse in &curses { | ||
result.push_str(&format!("{}\n", curse)); | ||
} | ||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
)] | ||
mod author; | ||
mod core; | ||
mod curse; | ||
mod repo; | ||
|
||
pub use crate::author::Author; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters