From 6b3ac348ac5ff60e422d4cee74faf7f1af0f5a69 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Thu, 26 Dec 2024 17:15:06 -0600 Subject: [PATCH] Fixed clippy suggestions --- dmp-core/src/music_controller/controller.rs | 14 +++-- .../music_storage/db_reader/itunes/reader.rs | 14 ++--- dmp-core/src/music_storage/library.rs | 53 ++++++++++--------- dmp-core/src/music_storage/playlist.rs | 6 +-- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/dmp-core/src/music_controller/controller.rs b/dmp-core/src/music_controller/controller.rs index 729922d..3a7e56f 100644 --- a/dmp-core/src/music_controller/controller.rs +++ b/dmp-core/src/music_controller/controller.rs @@ -168,8 +168,8 @@ impl ControllerHandle { }, ControllerInput { player_mail, - lib_mail: lib_mail, - queue_mail: queue_mail, + lib_mail, + queue_mail, library, config } @@ -237,8 +237,6 @@ impl Controller { } }; - let queue = queue; - std::thread::scope(|scope| { let queue_mail = queue_mail; let a = scope.spawn(|| { @@ -363,7 +361,7 @@ impl Controller { let LibraryResponse::AllSongs(songs) = lib_mail.recv().await.unwrap() else { unreachable!() }; - lib_mail.send(LibraryCommand::Song(np_song.song.uuid.clone())).await.unwrap(); + lib_mail.send(LibraryCommand::Song(np_song.song.uuid)).await.unwrap(); let LibraryResponse::Song(_, i) = lib_mail.recv().await.unwrap() else { unreachable!() }; @@ -436,7 +434,7 @@ impl Controller { let QueueResponse::Ok = queue_mail.recv().await.unwrap() else { unreachable!() }; - queue_mail.send(QueueCommand::Append(QueueItem::from_item_type(QueueItemType::Single(QueueSong { song: song.clone(), location: location })), true)).await.unwrap(); + queue_mail.send(QueueCommand::Append(QueueItem::from_item_type(QueueItemType::Single(QueueSong { song: song.clone(), location })), true)).await.unwrap(); let QueueResponse::Ok = queue_mail.recv().await.unwrap() else { unreachable!() }; @@ -508,11 +506,11 @@ impl Controller { }, LibraryCommand::ExternalPlaylist(uuid) => { let playlist = library.query_playlist_uuid(&uuid).unwrap(); - lib_mail.send(LibraryResponse::ExternalPlaylist(ExternalPlaylist::from_playlist(playlist, &library))).await.unwrap(); + lib_mail.send(LibraryResponse::ExternalPlaylist(ExternalPlaylist::from_playlist(playlist, library))).await.unwrap(); } LibraryCommand::ImportM3UPlayList(path) => { let playlist = Playlist::from_m3u(path, library).unwrap(); - let uuid = playlist.uuid.clone(); + let uuid = playlist.uuid; let name = playlist.title.clone(); library.playlists.items.push(PlaylistFolderItem::List(playlist)); diff --git a/dmp-core/src/music_storage/db_reader/itunes/reader.rs b/dmp-core/src/music_storage/db_reader/itunes/reader.rs index 4690b7f..d70496e 100644 --- a/dmp-core/src/music_storage/db_reader/itunes/reader.rs +++ b/dmp-core/src/music_storage/db_reader/itunes/reader.rs @@ -67,11 +67,11 @@ impl ExternalLibrary for ITunesLibrary { key_selected = false; //end the song to start a new one, and turn turn current song map into iTunesSong - if song_tags.contains_key(&"Location".to_string()) { + if song_tags.contains_key("Location") { count3 += 1; //check for skipped IDs if &count3.to_string() - != song_tags.get_key_value(&"Track ID".to_string()).unwrap().1 + != song_tags.get_key_value("Track ID").unwrap().1 { count3 += 1; count4 += 1; @@ -196,10 +196,7 @@ impl ExternalLibrary for ITunesLibrary { last_played: track.last_played, date_added: track.date_added, date_modified: track.date_modified, - album_art: match get_art(Path::new(&loc)) { - Ok(e) => e, - Err(_) => Vec::new(), - }, + album_art: get_art(Path::new(&loc)).unwrap_or_default(), tags: tags_, internal_tags, }; @@ -252,10 +249,7 @@ fn get_art(file: &Path) -> Result, lofty::error::LoftyError> { } Err(_) => blank_tag, }; - let mut img = match utils::find_images(file) { - Ok(e) => e, - Err(_) => Vec::new(), - }; + let mut img = utils::find_images(file).unwrap_or_default(); if !img.is_empty() { album_art.append(img.as_mut()); } diff --git a/dmp-core/src/music_storage/library.rs b/dmp-core/src/music_storage/library.rs index cd42bd2..808b1c2 100644 --- a/dmp-core/src/music_storage/library.rs +++ b/dmp-core/src/music_storage/library.rs @@ -7,6 +7,7 @@ use std::cmp::Ordering; // Various std things use std::collections::BTreeMap; use std::error::Error; +use std::fmt::Display; use std::io::Read; use std::ops::ControlFlow::{Break, Continue}; use std::vec::IntoIter; @@ -65,9 +66,10 @@ pub enum Tag { Field(String), } -impl ToString for Tag { - fn to_string(&self) -> String { - match self { + +impl Display for Tag { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let path_str: String = match self { Self::Title => "TrackTitle".into(), Self::Album => "AlbumTitle".into(), Self::Artist => "TrackArtist".into(), @@ -78,7 +80,9 @@ impl ToString for Tag { Self::Disk => "DiscNumber".into(), Self::Key(key) => key.into(), Self::Field(f) => f.into(), - } + }; + + write!(f, "{}", path_str) } } @@ -98,9 +102,9 @@ pub enum Field { DateModified(DateTime), } -impl ToString for Field { - fn to_string(&self) -> String { - match self { +impl Display for Field { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let path_str = match self { Self::Location(location) => location.to_string(), Self::Plays(plays) => plays.to_string(), Self::Skips(skips) => skips.to_string(), @@ -112,7 +116,9 @@ impl ToString for Field { Self::LastPlayed(last) => last.to_rfc2822(), Self::DateAdded(added) => added.to_rfc2822(), Self::DateModified(modified) => modified.to_rfc2822(), - } + }; + + write!(f, "{}", path_str) } } @@ -205,7 +211,7 @@ impl Song { "rating" => self.rating.map(Field::Rating), "duration" => Some(Field::Duration(self.duration)), "play_time" => Some(Field::PlayTime(self.play_time)), - "format" => self.format.clone().map(|m| Field::Format(m)), + "format" => self.format.clone().map(Field::Format), _ => todo!(), // Other field types are not yet supported } } @@ -220,7 +226,7 @@ impl Song { self.tags.remove(target_key); } - /// Creates a `Song` from a music file + /// Creates a [`Song`] from a music file pub fn from_file>(target_file: &P) -> Result> { let normal_options = lofty::config::ParseOptions::new().parsing_mode(lofty::config::ParsingMode::Relaxed); @@ -320,7 +326,7 @@ impl Song { Ok(new_song) } - /// creates a `Vec` from a cue file + /// creates a [`Vec`] from a cue file pub fn from_cue(cuesheet: &Path) -> Result, Box> { let mut tracks = Vec::new(); @@ -386,18 +392,14 @@ impl Song { // Get some useful tags let mut tags: BTreeMap = BTreeMap::new(); - match album_title { - Some(title) => { - tags.insert(Tag::Album, title.clone()); - } - None => (), + if let Some(title) = album_title { + tags.insert(Tag::Album, title.clone()); } - match album_artist { - Some(artist) => { - tags.insert(Tag::Artist, artist.clone()); - } - None => (), + + if let Some(artist) = album_artist { + tags.insert(Tag::Artist, artist.clone()); } + tags.insert(Tag::Track, track.no.parse().unwrap_or((i + 1).to_string())); match track.title.clone() { Some(title) => tags.insert(Tag::Title, title), @@ -573,14 +575,15 @@ impl URI { } } -impl ToString for URI { - fn to_string(&self) -> String { +impl Display for URI { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let path_str = match self { URI::Local(location) => location.as_path().to_string_lossy(), URI::Cue { location, .. } => location.as_path().to_string_lossy(), URI::Remote(_, location) => location.into(), }; - path_str.to_string() + + write!(f, "{}", path_str) } } @@ -629,7 +632,7 @@ impl Album { fn tracks(&self) -> Vec<(u16, Uuid)> { let mut songs = Vec::new(); for disc in self.discs.values() { - songs.extend_from_slice(&disc) + songs.extend_from_slice(disc) } songs } diff --git a/dmp-core/src/music_storage/playlist.rs b/dmp-core/src/music_storage/playlist.rs index 5307108..5131649 100644 --- a/dmp-core/src/music_storage/playlist.rs +++ b/dmp-core/src/music_storage/playlist.rs @@ -46,7 +46,7 @@ impl PlaylistFolder { match item { PlaylistFolderItem::Folder(folder) => return folder.query_uuid(uuid), PlaylistFolderItem::List(ref playlist) => if &playlist.uuid == uuid { - return Some(&playlist); + return Some(playlist); } } } @@ -368,7 +368,7 @@ impl ExternalPlaylist { }).collect_vec(); Self { - uuid: playlist.uuid.clone(), + uuid: playlist.uuid, title: playlist.title.clone(), tracks, sort_order: playlist.sort_order.clone(), @@ -381,7 +381,7 @@ impl ExternalPlaylist { let mut i = 0; if self.contains(uuid) { for track in &self.tracks { - if &uuid == &track.uuid { + if uuid == track.uuid { return Some(i); } i += 1;