From 7c7f3b888337950daabb6780590ee4a787bdd17c Mon Sep 17 00:00:00 2001 From: Lukas Dietrich Date: Thu, 31 Mar 2022 22:32:31 +0200 Subject: [PATCH] Apply clippy fixes --- src/controller/list.rs | 2 +- src/data/bartib_file.rs | 4 +--- src/view/format_util.rs | 2 +- src/view/report.rs | 8 ++------ 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/controller/list.rs b/src/controller/list.rs index 91bcc0f..a2edb87 100644 --- a/src/controller/list.rs +++ b/src/controller/list.rs @@ -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) ); } diff --git a/src/data/bartib_file.rs b/src/data/bartib_file.rs index 61ba76a..cde0b66 100644 --- a/src/data/bartib_file.rs +++ b/src/data/bartib_file.rs @@ -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()), diff --git a/src/view/format_util.rs b/src/view/format_util.rs index 0a606d2..6c83e6f 100644 --- a/src/view/format_util.rs +++ b/src/view/format_util.rs @@ -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 { diff --git a/src/view/report.rs b/src/view/report.rs index ecc3e18..814dd82 100644 --- a/src/view/report.rs +++ b/src/view/report.rs @@ -157,9 +157,7 @@ fn group_activities_by_description<'a>(activities: &'a [&'a activity::Activity]) fn get_longest_line(project_map: &ProjectMap) -> Option { 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 { .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();