From 91878512ca50a9535a1fc34a368b470a8c6e25ca Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Sat, 22 Apr 2023 09:02:14 +0200 Subject: [PATCH] [lint] Improve the code --- src/bin/cmus-notify.rs | 5 ++--- src/cmus/events.rs | 6 +++--- src/cmus/mod.rs | 10 +++++----- src/cmus/player_settings.rs | 2 +- src/cmus/query.rs | 10 +++++----- src/lib.rs | 4 ++-- src/notification.rs | 8 ++++---- src/settings.rs | 2 +- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/bin/cmus-notify.rs b/src/bin/cmus-notify.rs index 493ce52..d631548 100644 --- a/src/bin/cmus-notify.rs +++ b/src/bin/cmus-notify.rs @@ -1,8 +1,7 @@ use cmus_notify::{ - cmus::{self, events::CmusEvent, query::CmusQueryResponse}, - notification, settings, + cmus::{self, query::CmusQueryResponse}, + notification, settings::Settings, - track_cover, TrackCover, }; #[cfg(feature = "debug")] diff --git a/src/cmus/events.rs b/src/cmus/events.rs index 982cd68..622d381 100644 --- a/src/cmus/events.rs +++ b/src/cmus/events.rs @@ -1,6 +1,6 @@ -use crate::{process_template_placeholders, settings}; -use crate::cmus::{Track, TrackStatus}; -use crate::cmus::player_settings::{AAAMode, PlayerSettings, Shuffle}; +use crate::{process_template_placeholders}; +use crate::cmus::{Track}; +use crate::cmus::player_settings::{PlayerSettings}; use crate::notification::Action; use crate::settings::Settings; diff --git a/src/cmus/mod.rs b/src/cmus/mod.rs index a8d358d..49be5e6 100644 --- a/src/cmus/mod.rs +++ b/src/cmus/mod.rs @@ -112,7 +112,7 @@ impl TemplateProcessor for Track { if let Some(value) = match key.as_str() { "status" => Some(status.as_str()), "title" => Some(self.get_name()), - _ => self.metadata.get(&key), + _ => self.metadata.get(key), } { processed = processed.replace(&format!("{{{key}}}"), value); } @@ -200,13 +200,13 @@ impl TrackMetadata { /// This function will assume you processed the first 4 lines, and remove them from the iterator. /// /// and also assume the all tags is contained in the iterator. - fn parse<'a>(mut lines: impl Iterator + Debug) -> Self { + fn parse<'a>(lines: impl Iterator + Debug) -> Self { #[cfg(feature = "debug")] info!("Parsing track metadata from lines: {:?}", lines); let mut tags = HashMap::new(); - while let Some(line) = lines.next() { + for line in lines { #[cfg(feature = "debug")] debug!("Parsing line: {}", line); match line.trim().split_once(' ') { @@ -240,7 +240,7 @@ impl Track { .split('/') .last() .unwrap_or("") - .split_once(".") + .split_once('.') .unwrap_or(("", "")) .0 }) @@ -268,7 +268,7 @@ pub fn ping_cmus( let output = String::from_utf8(output.stdout).map_err(|e| CmusError::UnknownError(e.to_string()))?; - CmusQueryResponse::from_str(&output).map_err(|e| CmusError::UnknownError(e.to_string())) + CmusQueryResponse::from_str(&output).map_err(CmusError::UnknownError) } /// Build the query command. diff --git a/src/cmus/player_settings.rs b/src/cmus/player_settings.rs index d603a04..6d7031b 100644 --- a/src/cmus/player_settings.rs +++ b/src/cmus/player_settings.rs @@ -123,7 +123,7 @@ impl FromStr for PlayerSettings { debug!("Parsing line: {}", line); if line.starts_with("set ") { let line = &line[4..]; - let (key, value) = line.split_once(" ").ok_or(CmusError::UnknownError( + let (key, value) = line.split_once(' ').ok_or(CmusError::UnknownError( "Corrupted cmus response".to_string(), ))?; diff --git a/src/cmus/query.rs b/src/cmus/query.rs index d2e3e37..951cf20 100644 --- a/src/cmus/query.rs +++ b/src/cmus/query.rs @@ -71,8 +71,8 @@ impl CmusQueryResponse { #[cfg(feature = "debug")] debug!("Track changed: {:?} -> {:?}", other_track, track); events.push(CmusEvent::TrackChanged( - other_track.clone(), - other_player_settings.clone(), + other_track, + other_player_settings, )); // We don't need to check for other changes, since the track changed. return Ok(events); @@ -93,7 +93,7 @@ impl CmusQueryResponse { other_track.position, track.position ); events.push(CmusEvent::PositionChanged( - track.clone(), + track, other_player_settings.clone(), )); } @@ -244,8 +244,8 @@ mod tests { let player_settings = player_settings.unwrap(); assert_eq!(player_settings.aaa_mode, AAAMode::All); - assert_eq!(player_settings.repeat, true); - assert_eq!(player_settings.repeat_current, false); + assert!(player_settings.repeat); + assert!(!player_settings.repeat_current); assert_eq!(player_settings.shuffle, Shuffle::Off); assert_eq!(player_settings.volume.left, 17); assert_eq!(player_settings.volume.right, 17); diff --git a/src/lib.rs b/src/lib.rs index 135574f..a65d460 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,9 +170,9 @@ pub fn track_cover( } if !no_use_external_cover { - let (Ok(regx), path) = (match path.split("/").last() { + let (Ok(regx), path) = (match path.split('/').last() { Some(last_pat) if last_pat.contains("r#") => { - (regex::Regex::new(&*last_pat.replace("r#", "")), + (regex::Regex::new(&last_pat.replace("r#", "")), // Remove the last part of the path path.remove(path.len() - last_pat.len() - 1).to_string()) } diff --git a/src/notification.rs b/src/notification.rs index fa03664..46d5e24 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -1,11 +1,11 @@ #[cfg(feature = "debug")] -use log::{debug, info}; +use log::{info}; use notify_rust::Notification; -use crate::{process_template_placeholders, settings, track_cover, TrackCover}; -use crate::cmus::{TemplateProcessor, Track, TrackStatus}; +use crate::{track_cover, TrackCover}; +use crate::cmus::{TemplateProcessor, Track}; use crate::cmus::events::CmusEvent; -use crate::cmus::player_settings::PlayerSettings; + use crate::cmus::query::CmusQueryResponse; use crate::settings::Settings; diff --git a/src/settings.rs b/src/settings.rs index 85233ba..02bb989 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -373,7 +373,7 @@ impl Settings { .or(cfg.notification_static_cover); cfg.cover_path_template = args.cover_path_template.or(cfg.cover_path_template); #[cfg(feature = "lyrics")] - if args.lyrics_path != None { + if args.lyrics_path.is_some() { #[cfg(feature = "debug")] debug!("The user not override the lyrics_path, using the config's lyrics_path. lyrics_path: {:?}", cfg.lyrics_path); cfg.lyrics_path = args.lyrics_path;