Lints
All checks were successful
Cargo CI / Lint (pull_request) Successful in 1m7s
Cargo CI / Build and Test (pull_request) Successful in 2m3s

This commit is contained in:
Wojciech Kozlowski 2025-01-04 22:31:02 +01:00
parent e136103ead
commit 19f201e1ac
4 changed files with 22 additions and 25 deletions

View File

@ -89,7 +89,7 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
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<Artist> {
@ -149,10 +149,7 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
#[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);

View File

@ -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

View File

@ -21,7 +21,7 @@ impl CollectionFilter {
include && !except
}
fn filter_and(empty: bool, group: &Vec<Vec<AlbumField>>, album: &Album) -> bool {
fn filter_and(empty: bool, group: &[Vec<AlbumField>], 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<AlbumField>, 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(),
}

View File

@ -28,19 +28,15 @@ impl IAppInteractReload for AppMachine<ReloadState> {
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)
}