From ce13ca6a779ab78ebb7a44ce07f654ae55f4dee4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 21:38:10 -0400 Subject: [PATCH 01/13] Fixed some warnings --- src/song.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/song.rs b/src/song.rs index b024a62..2e29a64 100644 --- a/src/song.rs +++ b/src/song.rs @@ -170,10 +170,10 @@ impl Song { if randomize { let some_chars: String = String::from("abcdefghij0123456789"); - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); for _i in 0..filename_len { - let random_number: i32 = rng.gen_range(0..=19); + let random_number: i32 = rng.random_range(0..=19); let index = random_number as usize; let rando_char = some_chars.chars().nth(index); -- 2.43.0 From 5a4e27af39e960cb5500026c2a30d876aac00711 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 21:48:07 -0400 Subject: [PATCH 02/13] Clippy changes --- src/access_level.rs | 10 +++++----- src/coverart.rs | 8 ++------ src/login_result.rs | 2 +- src/song.rs | 24 +++++++++++------------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/access_level.rs b/src/access_level.rs index 2dc4f15..c41d81f 100644 --- a/src/access_level.rs +++ b/src/access_level.rs @@ -20,23 +20,23 @@ impl Default for AccessLevel { } pub fn default_level() -> AccessLevel { - return AccessLevel { + AccessLevel { id: -1, level: String::from("Public"), song_id: -1, - }; + } } pub fn private_level() -> AccessLevel { - return AccessLevel { + AccessLevel { id: -1, level: String::from("Private"), song_id: -1, - }; + } } impl AccessLevel { pub fn _to_json(&self) -> Result { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } } diff --git a/src/coverart.rs b/src/coverart.rs index 4703823..f8aaec5 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -16,12 +16,8 @@ impl CoverArt { let mut file = std::fs::File::open(path)?; let mut buffer = Vec::new(); match file.read_to_end(&mut buffer) { - Ok(_) => { - return Ok(buffer); - } - Err(err) => { - return Err(err); - } + Ok(_) => Ok(buffer), + Err(err) => Err(err), } } } diff --git a/src/login_result.rs b/src/login_result.rs index 9095fdb..782ca77 100644 --- a/src/login_result.rs +++ b/src/login_result.rs @@ -26,6 +26,6 @@ impl Default for LoginResult { impl LoginResult { pub fn _to_json(&self) -> Result { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } } diff --git a/src/song.rs b/src/song.rs index 2e29a64..64650ab 100644 --- a/src/song.rs +++ b/src/song.rs @@ -96,18 +96,18 @@ impl Default for Song { impl Song { pub fn to_metadata_json(&self, pretty: bool) -> Result { if pretty { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } else { - return serde_json::to_string(&self); + serde_json::to_string(&self) } } pub fn song_path(&self) -> Result { if self.directory.is_empty() { - return Err(std::io::Error::new( + Err(std::io::Error::new( std::io::ErrorKind::Other, "Directory does not exist", - )); + )) } let directory = &self.directory; @@ -121,12 +121,12 @@ impl Song { buffer += &self.filename.clone(); - return Ok(buffer); + Ok(buffer) } else { - return Err(std::io::Error::new( + Err(std::io::Error::new( std::io::ErrorKind::Other, "Could not access last character of directory", - )); + )) } } @@ -140,17 +140,15 @@ impl Song { file.read_to_end(&mut buffer)?; if buffer.len() == 0 { - return Err(std::io::Error::new( + Err(std::io::Error::new( std::io::ErrorKind::Other, "File is empty", - )); + )) } else { - return Ok(buffer); + Ok(buffer) } } - Err(er) => { - return Err(er); - } + Err(er) => Err(er), } } -- 2.43.0 From deb39dbfdcd2b7655fc38e7da201415d4e0f717d Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 21:50:30 -0400 Subject: [PATCH 03/13] Change to song to address warning fix --- src/song.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/song.rs b/src/song.rs index 64650ab..e3657da 100644 --- a/src/song.rs +++ b/src/song.rs @@ -104,10 +104,10 @@ impl Song { pub fn song_path(&self) -> Result { if self.directory.is_empty() { - Err(std::io::Error::new( + return Err(std::io::Error::new( std::io::ErrorKind::Other, "Directory does not exist", - )) + )); } let directory = &self.directory; -- 2.43.0 From d9bc2c5d09060d775667b089adcc4850f32269c5 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 21:55:15 -0400 Subject: [PATCH 04/13] More changes --- src/song.rs | 8 ++++---- src/user.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/song.rs b/src/song.rs index e3657da..e568a77 100644 --- a/src/song.rs +++ b/src/song.rs @@ -111,7 +111,7 @@ impl Song { } let directory = &self.directory; - let mut buffer: String = String::from(directory.clone()); + let mut buffer: String = directory.clone(); let last_index = directory.len() - 1; if let Some(character) = directory.chars().nth(last_index) { @@ -139,7 +139,7 @@ impl Song { let mut buffer: Vec = Vec::new(); file.read_to_end(&mut buffer)?; - if buffer.len() == 0 { + if buffer.is_empty() { Err(std::io::Error::new( std::io::ErrorKind::Other, "File is empty", @@ -215,7 +215,7 @@ mod embedded { } let directory = &self.directory; - let mut buffer: String = String::from(directory.clone()); + let mut buffer: String = directory.clone(); let last_index = directory.len() - 1; if let Some(character) = directory.chars().nth(last_index) { @@ -243,7 +243,7 @@ mod embedded { let mut buffer: Vec = Vec::new(); file.read_to_end(&mut buffer)?; - if buffer.len() == 0 { + if buffer.is_empty() { return Err(std::io::Error::new( std::io::ErrorKind::Other, "File is empty", diff --git a/src/user.rs b/src/user.rs index 04fe442..07f2a59 100644 --- a/src/user.rs +++ b/src/user.rs @@ -52,9 +52,9 @@ impl Default for User { impl User { pub fn to_json(&self, output_pretty: bool) -> Result { if output_pretty { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } else { - return serde_json::to_string(&self); + serde_json::to_string(&self) } } } -- 2.43.0 From c1761d5d5eb1640b78755356126012d78e80ed42 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 21:57:04 -0400 Subject: [PATCH 05/13] Token fix --- src/token.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/token.rs b/src/token.rs index 3934840..e92d13a 100644 --- a/src/token.rs +++ b/src/token.rs @@ -43,18 +43,18 @@ impl AccessToken { pub fn bearer_token(&self) -> String { let mut token: String = String::from("Bearer "); token += &self.token.clone(); - return token; + token } } impl Token { pub fn _to_json(&self) -> Result { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } // TODO: Implement pub fn token_expired(&self) -> bool { - return false; + false } // TODO: Implement @@ -62,9 +62,9 @@ impl Token { let extracted_token: String = String::from("Token"); if extracted_token == *des_scope { - return true; + true } - return false; + false } } -- 2.43.0 From e3ebf6d6741a3a79be864b81d07e4546ed988eb9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:00:04 -0400 Subject: [PATCH 06/13] Another one --- src/song.rs | 8 ++++---- src/token.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/song.rs b/src/song.rs index e568a77..d4abad9 100644 --- a/src/song.rs +++ b/src/song.rs @@ -244,16 +244,16 @@ mod embedded { file.read_to_end(&mut buffer)?; if buffer.is_empty() { - return Err(std::io::Error::new( + Err(std::io::Error::new( std::io::ErrorKind::Other, "File is empty", - )); + )) } else { - return Ok(buffer); + Ok(buffer) } } Err(er) => { - return Err(er); + Err(er) } } } diff --git a/src/token.rs b/src/token.rs index e92d13a..dc5a261 100644 --- a/src/token.rs +++ b/src/token.rs @@ -62,7 +62,7 @@ impl Token { let extracted_token: String = String::from("Token"); if extracted_token == *des_scope { - true + return true; } false -- 2.43.0 From c4b52aa31ad31d1d386b029bd9b561b9cfa5d729 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:03:33 -0400 Subject: [PATCH 07/13] Changing from match to let --- src/song.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/song.rs b/src/song.rs index d4abad9..a8e69d5 100644 --- a/src/song.rs +++ b/src/song.rs @@ -175,12 +175,9 @@ impl Song { let index = random_number as usize; let rando_char = some_chars.chars().nth(index); - match rando_char { - Some(c) => { - filename.push(c); - } - None => {} - }; + if let Some(c) = rando_char { + filename.push(c); + } } } else { filename += "track-output"; @@ -188,7 +185,7 @@ impl Song { filename += &file_extension; - return filename; + filename } } -- 2.43.0 From e3ec08963dcbce257aed46f38def6f295fed65bd Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:04:40 -0400 Subject: [PATCH 08/13] Another warning fix --- src/song.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/song.rs b/src/song.rs index a8e69d5..f88e6c0 100644 --- a/src/song.rs +++ b/src/song.rs @@ -224,10 +224,10 @@ mod embedded { return Ok(buffer); } else { - return Err(std::io::Error::new( + Err(std::io::Error::new( std::io::ErrorKind::Other, "Could not access last character of directory", - )); + )) } } @@ -249,9 +249,7 @@ mod embedded { Ok(buffer) } } - Err(er) => { - Err(er) - } + Err(er) => Err(er), } } } -- 2.43.0 From 928421fe1201c52c628370d705d2f398c345d513 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:06:40 -0400 Subject: [PATCH 09/13] More changes --- src/song.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/song.rs b/src/song.rs index f88e6c0..291b7f3 100644 --- a/src/song.rs +++ b/src/song.rs @@ -197,9 +197,9 @@ mod embedded { impl Song { pub fn to_metadata_json(&self, pretty: bool) -> Result { if pretty { - return serde_json::to_string_pretty(&self); + serde_json::to_string_pretty(&self) } else { - return serde_json::to_string(&self); + serde_json::to_string(&self) } } @@ -222,7 +222,7 @@ mod embedded { buffer += &self.filename.clone(); - return Ok(buffer); + Ok(buffer) } else { Err(std::io::Error::new( std::io::ErrorKind::Other, -- 2.43.0 From 0fe70500fa0748ccfbcc5f737655460979221ffd Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:12:14 -0400 Subject: [PATCH 10/13] Changed types --- src/song.rs | 10 +++++----- src/types.rs | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/song.rs b/src/song.rs index 291b7f3..f7d6651 100644 --- a/src/song.rs +++ b/src/song.rs @@ -152,18 +152,18 @@ impl Song { } } - pub fn generate_filename(&self, typ: types::types::Types, randomize: bool) -> String { + pub fn generate_filename(&self, typ: types::Types, randomize: bool) -> String { let mut filename: String = String::new(); let filename_len = 10; let file_extension = match typ { - types::types::Types::DefaultMusicExtension => { + types::Types::DefaultMusicExtension => { String::from(constants::DEFAULTMUSICEXTENSION) } - types::types::Types::WavExtension => String::from(constants::WAVEXTENSION), - types::types::Types::FlacExtension => String::from(constants::FLACEXTENSION), - types::types::Types::MPThreeExtension => String::from(constants::MPTHREEEXTENSION), + types::Types::WavExtension => String::from(constants::WAVEXTENSION), + types::Types::FlacExtension => String::from(constants::FLACEXTENSION), + types::Types::MPThreeExtension => String::from(constants::MPTHREEEXTENSION), }; if randomize { diff --git a/src/types.rs b/src/types.rs index 1cc0995..8d7c126 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,8 +1,6 @@ -pub mod types { pub enum Types { DefaultMusicExtension, WavExtension, FlacExtension, MPThreeExtension, } -} -- 2.43.0 From 6de1f9904c3196f8deb6f16e5e6018073354f191 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:12:25 -0400 Subject: [PATCH 11/13] Code formatting --- src/song.rs | 4 +--- src/types.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/song.rs b/src/song.rs index f7d6651..3546ae7 100644 --- a/src/song.rs +++ b/src/song.rs @@ -157,9 +157,7 @@ impl Song { let filename_len = 10; let file_extension = match typ { - types::Types::DefaultMusicExtension => { - String::from(constants::DEFAULTMUSICEXTENSION) - } + types::Types::DefaultMusicExtension => String::from(constants::DEFAULTMUSICEXTENSION), types::Types::WavExtension => String::from(constants::WAVEXTENSION), types::Types::FlacExtension => String::from(constants::FLACEXTENSION), diff --git a/src/types.rs b/src/types.rs index 8d7c126..d8892dc 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,7 @@ - pub enum Types { - DefaultMusicExtension, - WavExtension, - FlacExtension, - MPThreeExtension, - } + +pub enum Types { + DefaultMusicExtension, + WavExtension, + FlacExtension, + MPThreeExtension, +} -- 2.43.0 From 1a72dd87a336eed69f9d9f336f6d8f1cad499b7c Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 21 Mar 2025 22:14:52 -0400 Subject: [PATCH 12/13] Changed Types name --- src/song.rs | 12 +++++++----- src/types.rs | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/song.rs b/src/song.rs index 3546ae7..de158ab 100644 --- a/src/song.rs +++ b/src/song.rs @@ -152,16 +152,18 @@ impl Song { } } - pub fn generate_filename(&self, typ: types::Types, randomize: bool) -> String { + pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String { let mut filename: String = String::new(); let filename_len = 10; let file_extension = match typ { - types::Types::DefaultMusicExtension => String::from(constants::DEFAULTMUSICEXTENSION), + types::MusicTypes::DefaultMusicExtension => { + String::from(constants::DEFAULTMUSICEXTENSION) + } - types::Types::WavExtension => String::from(constants::WAVEXTENSION), - types::Types::FlacExtension => String::from(constants::FLACEXTENSION), - types::Types::MPThreeExtension => String::from(constants::MPTHREEEXTENSION), + types::MusicTypes::WavExtension => String::from(constants::WAVEXTENSION), + types::MusicTypes::FlacExtension => String::from(constants::FLACEXTENSION), + types::MusicTypes::MPThreeExtension => String::from(constants::MPTHREEEXTENSION), }; if randomize { diff --git a/src/types.rs b/src/types.rs index d8892dc..e518320 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,4 @@ - -pub enum Types { +pub enum MusicTypes { DefaultMusicExtension, WavExtension, FlacExtension, -- 2.43.0 From 6e4b2bd34b33afe89c9eab6d431acf3741a4c0fa Mon Sep 17 00:00:00 2001 From: KD Date: Sat, 22 Mar 2025 12:26:25 -0400 Subject: [PATCH 13/13] Removing embedded song model and default functions --- src/song.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/song.rs b/src/song.rs index de158ab..ed62435 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,4 +1,4 @@ -use std::default::Default; +// use std::default::Default; use std::io::Read; use crate::constants; @@ -64,6 +64,7 @@ fn is_dur_not_set(num: &i32) -> bool { *num == 0 } +/* impl Default for Song { fn default() -> Self { Song { @@ -92,6 +93,7 @@ impl Default for Song { } } } +*/ impl Song { pub fn to_metadata_json(&self, pretty: bool) -> Result { @@ -189,6 +191,7 @@ impl Song { } } +/* mod embedded { use std::io::Read; @@ -341,3 +344,4 @@ mod embedded { } } } +*/ -- 2.43.0