From 1e3c66679c35566980c6764bf1582b11843aa6d9 Mon Sep 17 00:00:00 2001 From: talwat <83217276+talwat@users.noreply.github.com> Date: Tue, 18 Feb 2025 21:48:30 +0200 Subject: [PATCH] fix: bug where text after ! in custom names wouldn't show up --- src/main.rs | 2 ++ src/player.rs | 6 ++++-- src/tracks.rs | 5 ++++- src/tracks/list.rs | 9 ++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4499d52..278baa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,8 @@ clippy::integer_division, clippy::cast_sign_loss, clippy::cast_lossless, + clippy::arbitrary_source_item_ordering, + clippy::unused_trait_names )] use clap::{Parser, Subcommand}; diff --git a/src/player.rs b/src/player.rs index fe2a132..209cb4b 100644 --- a/src/player.rs +++ b/src/player.rs @@ -187,7 +187,7 @@ impl Player { let volume = PersistentVolume::load().await?; // Load the track list. - let list = List::load(&args.tracks).await?; + let list = List::load(args.tracks.as_ref()).await?; // We should only shut up alsa forcefully on Linux if we really have to. #[cfg(target_os = "linux")] @@ -233,7 +233,9 @@ impl Player { /// /// This will also set `current` to the newly loaded song. pub async fn next(&self) -> eyre::Result { - let track = if let Some(track) = self.tracks.write().await.pop_front() { + // TODO: Consider replacing this with `unwrap_or_else` when async closures are stablized. + let track = self.tracks.write().await.pop_front(); + let track = if let Some(track) = track { track } else { // If the queue is completely empty, then fallback to simply getting a new track. diff --git a/src/tracks.rs b/src/tracks.rs index 0ad8167..2997f95 100644 --- a/src/tracks.rs +++ b/src/tracks.rs @@ -78,7 +78,10 @@ impl Info { if skip == formatted.len() { formatted } else { - #[allow(clippy::string_slice, /* We've already checked before that the bound is at an ASCII digit. */)] + #[expect( + clippy::string_slice, + reason = "We've already checked before that the bound is at an ASCII digit." + )] String::from(&formatted[skip..]) } } diff --git a/src/tracks/list.rs b/src/tracks/list.rs index 8cfe892..08be0bd 100644 --- a/src/tracks/list.rs +++ b/src/tracks/list.rs @@ -41,11 +41,10 @@ impl List { let random = rand::thread_rng().gen_range(1..self.lines.len()); let line = self.lines[random].clone(); - let split: Vec<&str> = line.split('!').collect(); - if split.len() == 1 { - (line, None) + if let Some((first, second)) = line.split_once('!') { + (first.to_owned(), Some(second.to_owned())) } else { - (split[0].to_owned(), Some(split[1].to_owned())) + (line, None) } } @@ -87,7 +86,7 @@ impl List { } /// Reads a [List] from the filesystem using the CLI argument provided. - pub async fn load(tracks: &Option) -> eyre::Result { + pub async fn load(tracks: Option<&String>) -> eyre::Result { if let Some(arg) = tracks { // Check if the track is in ~/.local/share/lowfi, in which case we'll load that. let name = dirs::data_dir()