Skip to content

Commit

Permalink
Make a fn return a bogus PodEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
fsktom committed Feb 18, 2023
1 parent 713f31e commit d9c58dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#![forbid(rustdoc::invalid_rust_codeblocks)]
#![forbid(rustdoc::bare_urls)]
#![forbid(clippy::pedantic)]
#![allow(clippy::cast_precision_loss)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::cast_possible_truncation)]

mod display;
mod parse;
Expand Down
14 changes: 10 additions & 4 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chrono::{DateTime, TimeZone};
use chrono_tz::Tz;
use serde::{Deserialize, Serialize};

use crate::types::SongEntry;
use crate::types::{PodEntry, SongEntry};

/// responsible for time zone handling
///
Expand Down Expand Up @@ -98,7 +98,7 @@ pub struct Entry {
fn parse_single(path: &str) -> Vec<SongEntry> {
let u = read_entries_from_file(path).unwrap_or_else(|_| panic!("File {} is invalid!", &path));
let mut songs: Vec<SongEntry> = Vec::new();
let mut podcasts: Vec<Entry> = Vec::new();
let mut podcasts: Vec<PodEntry> = Vec::new();
for entry in u {
match entry_to_songentry(entry) {
Ok(song) => songs.push(song),
Expand Down Expand Up @@ -134,11 +134,17 @@ fn read_entries_from_file<P: AsRef<Path>>(path: P) -> Result<Vec<Entry>, Box<dyn
}

/// Converts the genral [Entry] to a more specific [`SongEntry`]
fn entry_to_songentry(entry: Entry) -> Result<SongEntry, Entry> {
fn entry_to_songentry(entry: Entry) -> Result<SongEntry, PodEntry> {
// to remove podcast entries
// if the track is null, so are album and artist
if parse_option(entry.master_metadata_track_name.clone()) == "n/a" {
return Err(entry);
// TODO! properly... not just a placeholder
// bc clippy::pednatic complained about returning
// big Result<SongEntry, Entry> with Entry being biiig
let pod = PodEntry {
id: "666".to_string(),
};
return Err(pod);
}
Ok(SongEntry {
timestamp: parse_date(&entry.ts),
Expand Down
6 changes: 6 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ pub struct SongEntry {
/// Fundamental for the use of this program
pub struct SongEntries(Vec<SongEntry>);

/// [`SongEntry`] but for podcasts
pub struct PodEntry {
/// Spotify URI
pub id: String,
}

// https://users.rust-lang.org/t/how-can-i-return-reference-of-the-struct-field/36325/2
// so that when you use &self it refers to &self.0 (Vec<SongEntry>)
impl std::ops::Deref for SongEntries {
Expand Down

0 comments on commit d9c58dc

Please sign in to comment.