From 8ba9f22430802d424eaf2597e42ab1f9d8d6740e Mon Sep 17 00:00:00 2001 From: Jana Lemke Date: Wed, 24 May 2023 11:11:12 +0200 Subject: [PATCH] Fix clippy lints --- src/config.rs | 8 +------- src/courses.rs | 2 +- src/main.rs | 10 +++------- src/rofi.rs | 3 +-- src/util.rs | 2 +- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index bffce13..5add9f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,14 +9,8 @@ pub struct Config { pub note_extensions: Vec, } -#[derive(StructOpt)] +#[derive(StructOpt, Default)] pub struct ListOptions { #[structopt(short, long)] pub all: bool, } - -impl Default for ListOptions { - fn default() -> Self { - ListOptions { all: false } - } -} diff --git a/src/courses.rs b/src/courses.rs index f85e5cd..a17959a 100644 --- a/src/courses.rs +++ b/src/courses.rs @@ -72,7 +72,7 @@ impl Course { let mut coursestring = String::new(); handle = File::open(&path).unwrap(); handle.read_to_string(&mut coursestring).unwrap(); - let mut course: Course = toml::from_str(&coursestring).expect(&format!("{:?}", &path)); + let mut course: Course = toml::from_str(&coursestring)?; course.path = path.parent().unwrap().to_path_buf(); if options.all || course.is_current() { courses.push(course); diff --git a/src/main.rs b/src/main.rs index 14f953f..eb6d9dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,16 +116,12 @@ fn list_lectures(conf: &Config, options: ListOptions) -> Result> { let lectures = lectures? .into_iter() - .filter_map(|path| { + .filter(|path| { if let Some(ext) = path.extension() { let ext = ext.to_owned().to_string_lossy().into(); - if conf.note_extensions.contains(&ext) { - Some(path) - } else { - None - } + conf.note_extensions.contains(&ext) } else { - None + false } }) .collect(); diff --git a/src/rofi.rs b/src/rofi.rs index 2d060c2..e304e66 100644 --- a/src/rofi.rs +++ b/src/rofi.rs @@ -20,7 +20,7 @@ pub fn select_meeting(conf: &Config, options: &ListOptions) -> Result<()> { let meetings: Vec<_> = Course::list(conf, options)? .iter() .cloned() - .map(|c: Course| { + .flat_map(|c: Course| { if let Some(meetings) = c.meetings() { meetings.clone() } else { @@ -30,7 +30,6 @@ pub fn select_meeting(conf: &Config, options: &ListOptions) -> Result<()> { .map(move |m| (c.clone(), m.clone())) .collect::>() }) - .flatten() .collect(); let meeting_names: Vec<_> = meetings .iter() diff --git a/src/util.rs b/src/util.rs index 4b39424..927b565 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use std::time::SystemTime; pub fn to_snail_case(from: impl Into) -> String { - from.into().replace(" ", "_").to_lowercase() + from.into().replace(' ', "_").to_lowercase() } // pub fn to_title_case(from: &str) -> String {