From 19f201e1ac541bfd022a57437ad8a41f8acf4962 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 4 Jan 2025 22:31:02 +0100 Subject: [PATCH] Lints --- src/core/musichoard/base.rs | 25 ++++++++++++------------- src/core/musichoard/builder.rs | 4 +++- src/core/musichoard/filter.rs | 6 +++--- src/tui/app/machine/reload_state.rs | 12 ++++-------- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/core/musichoard/base.rs b/src/core/musichoard/base.rs index 1ec0534..08a04c7 100644 --- a/src/core/musichoard/base.rs +++ b/src/core/musichoard/base.rs @@ -89,7 +89,7 @@ impl IMusicHoardBasePrivate for MusicHoard fn filter_collection(&self) -> Collection { let iter = self.collection.iter(); - iter.map(|a| self.filter_artist(a)).flatten().collect() + iter.flat_map(|a| self.filter_artist(a)).collect() } fn filter_artist(&self, artist: &Artist) -> Option { @@ -149,10 +149,7 @@ impl IMusicHoardBasePrivate for MusicHoard #[cfg(test)] mod tests { use crate::{ - collection::{ - album::{AlbumMeta, AlbumPrimaryType}, - artist::ArtistMeta, - }, + collection::{album::AlbumPrimaryType, artist::ArtistMeta}, core::testmod::FULL_COLLECTION, filter::AlbumField, }; @@ -331,14 +328,16 @@ mod tests { #[test] fn filtered() { - let mut mh = MusicHoard::default(); - mh.collection = vec![Artist { - meta: ArtistMeta::new(ArtistId::new("Artist")), - albums: vec![ - Album::new(AlbumId::new("Album 1")), - Album::new(AlbumId::new("Album 2")), - ], - }]; + let mut mh = MusicHoard { + collection: vec![Artist { + meta: ArtistMeta::new(ArtistId::new("Artist")), + albums: vec![ + Album::new(AlbumId::new("Album 1")), + Album::new(AlbumId::new("Album 2")), + ], + }], + ..Default::default() + }; mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Ep); mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Album); diff --git a/src/core/musichoard/builder.rs b/src/core/musichoard/builder.rs index a68aac9..1901a9f 100644 --- a/src/core/musichoard/builder.rs +++ b/src/core/musichoard/builder.rs @@ -1,6 +1,8 @@ use crate::core::{ interface::{database::IDatabase, library::ILibrary}, - musichoard::{database::IMusicHoardDatabase, Error, MusicHoard, NoDatabase, NoLibrary, CollectionFilter}, + musichoard::{ + database::IMusicHoardDatabase, CollectionFilter, Error, MusicHoard, NoDatabase, NoLibrary, + }, }; /// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of diff --git a/src/core/musichoard/filter.rs b/src/core/musichoard/filter.rs index 8e9f21e..c1b317f 100644 --- a/src/core/musichoard/filter.rs +++ b/src/core/musichoard/filter.rs @@ -21,7 +21,7 @@ impl CollectionFilter { include && !except } - fn filter_and(empty: bool, group: &Vec>, album: &Album) -> bool { + fn filter_and(empty: bool, group: &[Vec], album: &Album) -> bool { let mut filter = !group.is_empty() || empty; for field in group.iter() { filter = filter && Self::filter_or(field, album); @@ -29,7 +29,7 @@ impl CollectionFilter { filter } - fn filter_or(group: &Vec, album: &Album) -> bool { + fn filter_or(group: &[AlbumField], album: &Album) -> bool { let mut filter = false; for field in group.iter() { filter = filter || Self::filter_field(field, album); @@ -42,7 +42,7 @@ impl CollectionFilter { AlbumField::PrimaryType(filter) => *filter == album.meta.info.primary_type, AlbumField::SecondaryType(filter) => { let types = &album.meta.info.secondary_types; - types.iter().find(|st| *st == filter).is_some() + types.iter().any(|st| st == filter) } AlbumField::Ownership(filter) => *filter == album.get_ownership(), } diff --git a/src/tui/app/machine/reload_state.rs b/src/tui/app/machine/reload_state.rs index deea728..7be5033 100644 --- a/src/tui/app/machine/reload_state.rs +++ b/src/tui/app/machine/reload_state.rs @@ -28,19 +28,15 @@ impl IAppInteractReload for AppMachine { type APP = App; fn reload_library(mut self) -> Self::APP { - let previous = KeySelection::get( - self.inner.music_hoard.get_filtered(), - &self.inner.selection, - ); + let previous = + KeySelection::get(self.inner.music_hoard.get_filtered(), &self.inner.selection); let result = self.inner.music_hoard.rescan_library(); self.refresh(previous, result) } fn reload_database(mut self) -> Self::APP { - let previous = KeySelection::get( - self.inner.music_hoard.get_filtered(), - &self.inner.selection, - ); + let previous = + KeySelection::get(self.inner.music_hoard.get_filtered(), &self.inner.selection); let result = self.inner.music_hoard.reload_database(); self.refresh(previous, result) }