Apply clippy fixes

This commit is contained in:
Lukas Dietrich 2022-03-31 22:32:31 +02:00
parent 1c3f3ff495
commit 7c7f3b8883
4 changed files with 5 additions and 11 deletions

View file

@ -70,7 +70,7 @@ pub fn check(file_name: &str) -> Result<()> {
println!(
"\n{}\n -> {} (Line: {})",
line.plaintext.as_ref().unwrap(),
e.to_string(),
e,
line.line_number.unwrap_or(0)
);
}

View file

@ -28,9 +28,7 @@ pub struct Line {
impl Line {
// creates a new line struct from plaintext
pub fn new(plaintext: &str, line_number: usize, preceeding_line: Option<&Line>) -> Line {
let preceeding_activity = preceeding_line
.map(|line| line.activity.as_ref().ok())
.flatten();
let preceeding_activity = preceeding_line.and_then(|line| line.activity.as_ref().ok());
Line {
plaintext: Some(plaintext.trim().to_string()),

View file

@ -4,7 +4,7 @@ pub fn format_duration(duration: &Duration) -> String {
let mut duration_string = String::new();
if duration.num_hours() > 0 {
duration_string.push_str(&format!("{}h ", duration.num_hours().to_string()));
duration_string.push_str(&format!("{}h ", duration.num_hours()));
}
if duration.num_minutes() > 0 {

View file

@ -157,9 +157,7 @@ fn group_activities_by_description<'a>(activities: &'a [&'a activity::Activity])
fn get_longest_line(project_map: &ProjectMap) -> Option<usize> {
let longest_project_line = project_map.keys().map(|p| p.chars().count()).max();
let longest_activity_line = project_map.values()
.map(|(a, _d)| a)
.flatten()
let longest_activity_line = project_map.values().flat_map(|(a, _d)| a)
.map(|a| a.description.chars().count() + conf::REPORT_INDENTATION).max();
get_max_option(longest_project_line, longest_activity_line)
}
@ -169,9 +167,7 @@ fn get_longest_duration_string(report: &Report) -> Option<usize> {
.map(|(_a, d)| format_util::format_duration(d))
.map(|s| s.chars().count())
.max();
let longest_activity_duration = report.project_map.values()
.map(|(a, _d)| a)
.flatten()
let longest_activity_duration = report.project_map.values().flat_map(|(a, _d)| a)
.map(|a| format_util::format_duration(&a.get_duration()))
.map(|s| s.chars().count())
.max();