From c9ea18f9ec7cb3d8ec5f8091cffcf7fb697a2104 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:37:18 -0400 Subject: [PATCH 1/6] tsk-76: Adding function to simplify getting path of Song --- src/constants.rs | 6 ++++++ src/song.rs | 10 ++++++++-- src/util/mod.rs | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/util/mod.rs diff --git a/src/constants.rs b/src/constants.rs index 4a982b1..4432a85 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -12,3 +12,9 @@ pub mod file_extensions { pub const PNGEXTENSION: &str = ".png"; } } + +pub mod error { + pub const DIRECTORY_NOT_INITIALIZED: &str = "Directory has not been initialized"; + pub const FILENAME_NOT_INITIALIZED: &str = "Filename has not bee initialized"; + pub const LAST_CHARACTER_IN_DIRECTORY: &str = "Could not access last character of directory"; +} diff --git a/src/song.rs b/src/song.rs index 5d5f35d..5254c83 100644 --- a/src/song.rs +++ b/src/song.rs @@ -71,14 +71,15 @@ impl Song { pub fn song_path(&self) -> Result { if self.directory.is_empty() { - return Err(std::io::Error::other("Directory has not been initialized")); + return Err(std::io::Error::other(crate::constants::error::DIRECTORY_NOT_INITIALIZED)); } else if self.filename.is_empty() { - return Err(std::io::Error::other("Filename has not bee initialized")); + return Err(std::io::Error::other(crate::constants::error::FILENAME_NOT_INITIALIZED)); } let directory = &self.directory; let last_index = directory.len() - 1; + /* if let Some(character) = directory.chars().nth(last_index) { let buffer: String = if character != '/' { directory.clone() + "/" @@ -92,6 +93,11 @@ impl Song { "Could not access last character of directory", )) } + */ + match crate::util::concatenate_path(&directory, &self.filename, last_index) { + Ok(path) => Ok(path), + Err(err) => Err(err) + } } /// Saves the song to the filesystem using the song's data diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..8543f65 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,13 @@ +pub fn concatenate_path(directory: &str, filename: &str, last_index: usize) -> Result { + if let Some(character) = directory.chars().nth(last_index) { + let buffer: String = if character != '/' { + format!("{directory}/") + } else { + String::from(directory) + }; + + Ok(format!("{buffer}{filename}")) + } else { + Err(std::io::Error::other(crate::constants::error::LAST_CHARACTER_IN_DIRECTORY)) + } +} -- 2.43.0 From f66436472a7be8f7afa41ed3e109ec6d9486c49d Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:37:33 -0400 Subject: [PATCH 2/6] tsk-76: Added util module --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index e328cf2..f4fcab5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ pub mod song; pub mod token; pub mod types; pub mod user; +pub mod util; pub mod init { pub fn is_id_valid(num: &i32) -> bool { -- 2.43.0 From 69423d8d3960de6fe1de9c51eb16f459cea03701 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:40:34 -0400 Subject: [PATCH 3/6] tsk-76: Cleanup --- src/coverart.rs | 23 +++++++++-------------- src/song.rs | 26 ++++++++------------------ src/util/mod.rs | 10 ++++++++-- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/coverart.rs b/src/coverart.rs index 0d50feb..23c3740 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -68,26 +68,21 @@ impl CoverArt { /// Gets the path of the CoverArt pub fn get_path(&self) -> Result { if self.directory.is_empty() { - return Err(std::io::Error::other("Directory has not been initialized")); + return Err(std::io::Error::other( + crate::constants::error::DIRECTORY_NOT_INITIALIZED, + )); } else if self.filename.is_empty() { - return Err(std::io::Error::other("Filename has not bee initialized")); + return Err(std::io::Error::other( + crate::constants::error::FILENAME_NOT_INITIALIZED, + )); } let directory = &self.directory; let last_index = directory.len() - 1; - if let Some(character) = directory.chars().nth(last_index) { - let buffer = if character != '/' { - directory.clone() + "/" - } else { - directory.clone() - }; - - Ok(buffer + &self.filename.clone()) - } else { - Err(std::io::Error::other( - "Could not access last character of directory", - )) + match crate::util::concatenate_path(&directory, &self.filename, last_index) { + Ok(path) => Ok(path), + Err(err) => Err(err), } } } diff --git a/src/song.rs b/src/song.rs index 5254c83..cf22272 100644 --- a/src/song.rs +++ b/src/song.rs @@ -69,34 +69,24 @@ impl Song { } } + /// Gets the path of a Song pub fn song_path(&self) -> Result { if self.directory.is_empty() { - return Err(std::io::Error::other(crate::constants::error::DIRECTORY_NOT_INITIALIZED)); + return Err(std::io::Error::other( + crate::constants::error::DIRECTORY_NOT_INITIALIZED, + )); } else if self.filename.is_empty() { - return Err(std::io::Error::other(crate::constants::error::FILENAME_NOT_INITIALIZED)); + return Err(std::io::Error::other( + crate::constants::error::FILENAME_NOT_INITIALIZED, + )); } let directory = &self.directory; let last_index = directory.len() - 1; - /* - if let Some(character) = directory.chars().nth(last_index) { - let buffer: String = if character != '/' { - directory.clone() + "/" - } else { - directory.clone() - }; - - Ok(buffer + &self.filename.clone()) - } else { - Err(std::io::Error::other( - "Could not access last character of directory", - )) - } - */ match crate::util::concatenate_path(&directory, &self.filename, last_index) { Ok(path) => Ok(path), - Err(err) => Err(err) + Err(err) => Err(err), } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 8543f65..983edbd 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,4 +1,8 @@ -pub fn concatenate_path(directory: &str, filename: &str, last_index: usize) -> Result { +pub fn concatenate_path( + directory: &str, + filename: &str, + last_index: usize, +) -> Result { if let Some(character) = directory.chars().nth(last_index) { let buffer: String = if character != '/' { format!("{directory}/") @@ -8,6 +12,8 @@ pub fn concatenate_path(directory: &str, filename: &str, last_index: usize) -> R Ok(format!("{buffer}{filename}")) } else { - Err(std::io::Error::other(crate::constants::error::LAST_CHARACTER_IN_DIRECTORY)) + Err(std::io::Error::other( + crate::constants::error::LAST_CHARACTER_IN_DIRECTORY, + )) } } -- 2.43.0 From fb7332e9ca11d095a6890ac92aea33940a2603cf Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:40:43 -0400 Subject: [PATCH 4/6] tsk-76: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1298cee..8e46098 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,7 +149,7 @@ checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "icarus_models" -version = "0.8.1" +version = "0.8.2" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 8c04753..8221e38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.8.1" +version = "0.8.2" edition = "2024" rust-version = "1.90" description = "models used for the icarus project" -- 2.43.0 From 6d2e2cb8500ccb1890bead9a266f43a71d227f9a Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:43:23 -0400 Subject: [PATCH 5/6] tsk-76: Warning fix --- src/coverart.rs | 2 +- src/song.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coverart.rs b/src/coverart.rs index 23c3740..c74752f 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -80,7 +80,7 @@ impl CoverArt { let directory = &self.directory; let last_index = directory.len() - 1; - match crate::util::concatenate_path(&directory, &self.filename, last_index) { + match crate::util::concatenate_path(directory, &self.filename, last_index) { Ok(path) => Ok(path), Err(err) => Err(err), } diff --git a/src/song.rs b/src/song.rs index cf22272..8e734e6 100644 --- a/src/song.rs +++ b/src/song.rs @@ -84,7 +84,7 @@ impl Song { let directory = &self.directory; let last_index = directory.len() - 1; - match crate::util::concatenate_path(&directory, &self.filename, last_index) { + match crate::util::concatenate_path(directory, &self.filename, last_index) { Ok(path) => Ok(path), Err(err) => Err(err), } -- 2.43.0 From 66c3cc898212404ec086ba53d90abe3a80d1972f Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 24 Oct 2025 12:47:13 -0400 Subject: [PATCH 6/6] Updated readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dfacd68..5e931ed 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -A library containing commonly used models and functions that is used throughout -icarus projects. This reduces the amount of duplicated code without a benefit. +A library containing commonly used structs, functions, enums, constants and other code +that is used throughout the icarus projects. Code from this library serves as the model +for other projects in the icarus project. -- 2.43.0