From 0b15ce8e1bda9c49fd08d656d27b3aeb4dc15521 Mon Sep 17 00:00:00 2001 From: Tal <83217276+talwat@users.noreply.github.com> Date: Wed, 2 Jul 2025 19:46:17 +0200 Subject: [PATCH] chore: give better names to track structs --- src/player.rs | 2 +- src/player/bookmark.rs | 2 ++ src/player/queue.rs | 2 +- src/tracks.rs | 22 ++++++++++++---------- src/tracks/list.rs | 6 +++--- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/player.rs b/src/player.rs index 9ed8e34..eb6549d 100644 --- a/src/player.rs +++ b/src/player.rs @@ -71,7 +71,7 @@ pub struct Player { /// *undecoded* [Track]s. /// /// This is populated specifically by the [Downloader]. - tracks: RwLock>, + tracks: RwLock>, /// The actual list of tracks to be played. list: List, diff --git a/src/player/bookmark.rs b/src/player/bookmark.rs index 0901f7d..393cd0e 100644 --- a/src/player/bookmark.rs +++ b/src/player/bookmark.rs @@ -18,6 +18,8 @@ pub async fn bookmark(path: String, custom: Option) -> eyre::Result Result { + async fn fetch(&self) -> Result { // 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 { diff --git a/src/tracks.rs b/src/tracks.rs index 1c33cff..e0ffb0c 100644 --- a/src/tracks.rs +++ b/src/tracks.rs @@ -8,7 +8,7 @@ //! First Stage, when a track is initially fetched. //! 1. Raw entry selected from track list. //! 2. Raw entry split into path & display name. -//! 3. Track data fetched, and [`Track`] is created which includes a [`TrackName`] that may be raw. +//! 3. Track data fetched, and [`QueuedTrack`] is created which includes a [`TrackName`] that may be raw. //! //! Second Stage, when a track is played. //! 1. Track data is decoded. @@ -73,8 +73,10 @@ pub enum TrackName { Formatted(String), } -/// The main track struct, which only includes data & the track name. -pub struct Track { +/// Tracks which are still waiting in the queue, and can't be played yet. +/// +/// This means that only the data & track name are included. +pub struct QueuedTrack { /// Name of the track, which may be raw. pub name: TrackName, @@ -86,12 +88,12 @@ pub struct Track { pub data: Bytes, } -impl Track { +impl QueuedTrack { /// This will actually decode and format the track, /// returning a [`DecodedTrack`] which can be played /// and also has a duration & formatted name. - pub fn decode(self) -> eyre::Result { - Decoded::new(self) + pub fn decode(self) -> eyre::Result { + DecodedTrack::new(self) } } @@ -198,7 +200,7 @@ impl Info { /// This struct is seperate from [Track] since it is generated lazily from /// a track, and not when the track is first downloaded. -pub struct Decoded { +pub struct DecodedTrack { /// Has both the formatted name and some information from the decoded data. pub info: Info, @@ -206,10 +208,10 @@ pub struct Decoded { pub data: DecodedData, } -impl Decoded { +impl DecodedTrack { /// Creates a new track. - /// This is equivalent to [`Track::decode`]. - pub fn new(track: Track) -> eyre::Result { + /// This is equivalent to [`QueuedTrack::decode`]. + pub fn new(track: QueuedTrack) -> eyre::Result { let data = Decoder::new(Cursor::new(track.data))?; let info = Info::new(track.name, track.full_path, &data)?; diff --git a/src/tracks/list.rs b/src/tracks/list.rs index 181a151..b41af93 100644 --- a/src/tracks/list.rs +++ b/src/tracks/list.rs @@ -9,7 +9,7 @@ use tokio::fs; use crate::{data_dir, tracks::TrackError}; -use super::Track; +use super::QueuedTrack; /// Represents a list of tracks that can be played. /// @@ -93,7 +93,7 @@ impl List { /// /// The Result's error is a bool, which is true if a timeout error occured, /// and false otherwise. This tells lowfi if it shouldn't wait to try again. - pub async fn random(&self, client: &Client) -> Result { + pub async fn random(&self, client: &Client) -> Result { let (path, custom_name) = self.random_path(); let (data, full_path) = self.download(&path, client).await?; @@ -101,7 +101,7 @@ impl List { super::TrackName::Formatted(formatted) }); - Ok(Track { + Ok(QueuedTrack { name, data, full_path,