From fef12e239c1a7f49d5b8ffd009a47cfc661939a5 Mon Sep 17 00:00:00 2001 From: Polochon_street Date: Tue, 18 Jun 2024 18:11:08 +0200 Subject: [PATCH] Use new iterators --- CHANGELOG.md | 3 +++ Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- src/main.rs | 32 ++++++++++++++++++-------------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd5075..11b9b36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## blissify 0.4.1 +* Make the "--seed-song" option return faster. + ## blissify 0.4.0 * Add a "--keep-current-queue" flag that keeps the current queue while making playlists, instead of automatically cropping it. diff --git a/Cargo.lock b/Cargo.lock index ff8e22d..25e5fcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,9 +101,9 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bliss-audio" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd556b69b31eeeecc5a52bc8ff99cf77be170f87495e7b7c8875be92064e54b" +checksum = "4550feb2d2272cf8fe47d41217ce8f82e17c4d91843a2ee68b79a0b5ac1cc011" dependencies = [ "adler32", "anyhow", @@ -149,7 +149,7 @@ dependencies = [ [[package]] name = "blissify" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "bliss-audio", diff --git a/Cargo.toml b/Cargo.toml index cb39a31..f076cc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blissify" -version = "0.4.0" +version = "0.4.1" authors = ["Polochon-street "] edition = "2021" license = "GPL-3.0-only" @@ -17,7 +17,7 @@ default = ["bliss-audio/library"] rpi = ["bliss-audio/rpi"] [dependencies] -bliss-audio = "0.7.0" +bliss-audio = "0.8.0" mpd = "0.0.12" dirs = "3.0.1" tempdir = "0.3.7" diff --git a/src/main.rs b/src/main.rs index 3a31ac1..7a56f8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -439,18 +439,19 @@ impl MPDLibrary { /// the playlist after the current song, but will keep the queue intact. // TODO do we want a flag to toggle "random" off automatically here? And a flag to keep / // exclude the current song from the playlist? - fn queue_from_song( + fn queue_from_song<'a, F, I>( &self, song_path: Option<&str>, number_songs: usize, - distance: &dyn DistanceMetricBuilder, - mut sort_by: F, + distance: &'a dyn DistanceMetricBuilder, + sort_by: F, dedup: bool, dry_run: bool, keep_queue: bool, ) -> Result<()> where - F: FnMut(&[LibrarySong<()>], &mut [LibrarySong<()>], &dyn DistanceMetricBuilder), + F: Fn(&[LibrarySong<()>], &[LibrarySong<()>], &'a dyn DistanceMetricBuilder) -> I, + I: Iterator> + 'a, { let mut mpd_conn = self.mpd_conn.lock().unwrap(); if mpd_conn.status()?.random { @@ -480,13 +481,11 @@ impl MPDLibrary { } else { number_songs + 1 }; - let playlist = self.library.playlist_from_custom( - &[&path.to_string_lossy().clone()], - number_songs, - distance, - &mut sort_by, - dedup, - )?; + let playlist: Vec> = self + .library + .playlist_from_custom(&[&path.to_string_lossy().clone()], distance, sort_by, dedup)? + .take(number_songs) + .collect(); if dry_run { for song in &playlist { @@ -967,9 +966,14 @@ Defaults to 3, cannot be more than 9." euclidean_distance }; - let sort = match sub_m.is_present("seed") { - false => closest_to_songs, - true => song_to_song, + let sort = |x: &[LibrarySong<()>], + y: &[LibrarySong<()>], + z| + -> Box>> { + match sub_m.is_present("seed") { + false => Box::new(closest_to_songs(x, y, z)), + true => Box::new(song_to_song(x, y, z)), + } }; library.queue_from_song( sub_m.value_of("from-song"),