chore: give better names to track structs

This commit is contained in:
Tal 2025-07-02 19:46:17 +02:00
parent 6fadfe6304
commit 0b15ce8e1b
5 changed files with 19 additions and 15 deletions

View File

@ -71,7 +71,7 @@ pub struct Player {
/// *undecoded* [Track]s.
///
/// This is populated specifically by the [Downloader].
tracks: RwLock<VecDeque<tracks::Track>>,
tracks: RwLock<VecDeque<tracks::QueuedTrack>>,
/// The actual list of tracks to be played.
list: List,

View File

@ -18,6 +18,8 @@ pub async fn bookmark(path: String, custom: Option<String>) -> eyre::Result<bool
let data_dir = data_dir()?;
create_dir_all(data_dir.clone()).await?;
// TODO: Only open and close the file at startup and shutdown, not every single bookmark.
// TODO: Sort of like PersistentVolume, but for bookmarks.
let mut file = OpenOptions::new()
.create(true)
.write(true)

View File

@ -10,7 +10,7 @@ use crate::{
impl Player {
/// Fetches the next track from the queue, or a random track if the queue is empty.
/// This will also set the current track to the fetched track's info.
async fn fetch(&self) -> Result<tracks::Decoded, tracks::TrackError> {
async fn fetch(&self) -> Result<tracks::DecodedTrack, tracks::TrackError> {
// 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 {

View File

@ -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, TrackError> {
Decoded::new(self)
pub fn decode(self) -> eyre::Result<DecodedTrack, TrackError> {
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<Self, TrackError> {
/// This is equivalent to [`QueuedTrack::decode`].
pub fn new(track: QueuedTrack) -> eyre::Result<Self, TrackError> {
let data = Decoder::new(Cursor::new(track.data))?;
let info = Info::new(track.name, track.full_path, &data)?;

View File

@ -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<Track, TrackError> {
pub async fn random(&self, client: &Client) -> Result<QueuedTrack, TrackError> {
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,