From 3e96bea7beffa17b81cb54edc0272f5db698335b Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 1 Jul 2025 22:23:37 -0400 Subject: [PATCH] Warning fixes --- src/help.rs | 2 +- src/main.rs | 4 ++-- src/syncers/common.rs | 14 ++++++++---- src/syncers/delete.rs | 10 ++++----- src/syncers/download.rs | 15 +++++++------ src/syncers/retrieve_records.rs | 18 ++++++++-------- src/syncers/upload.rs | 38 ++++++++++++++++----------------- src/utilities/checks.rs | 4 ++-- src/utilities/string.rs | 3 +-- 9 files changed, 57 insertions(+), 51 deletions(-) diff --git a/src/help.rs b/src/help.rs index 49ba02f..357d22f 100644 --- a/src/help.rs +++ b/src/help.rs @@ -32,5 +32,5 @@ pub fn print_help() { -D song id"#, ); - println!("{}", msg); + println!("{msg}"); } diff --git a/src/main.rs b/src/main.rs index c47d149..1a3c2b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ fn main() { utilities::checks::exit_program(-1); } - println!("Argument count: {}", args_len); + println!("Argument count: {args_len}"); let mut act_mgr = managers::action_managers::ActionManager::default(); act_mgr.set_params(&args); @@ -41,7 +41,7 @@ mod tests { let meta_path = String::from("tests/sample2_tracks/album.json"); if !std::path::Path::new(&meta_path).exists() { - assert!(false, "File does not exists: {:?}", meta_path); + assert!(false, "File does not exists: {:meta_path?}"); } match icarus_models::album::collection::parse_album(&meta_path) { diff --git a/src/syncers/common.rs b/src/syncers/common.rs index 59933ca..9d632a6 100644 --- a/src/syncers/common.rs +++ b/src/syncers/common.rs @@ -2,13 +2,14 @@ use crate::models; pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> String { if with_id { - retrieve_url_with_id(&api, id) + retrieve_url_with_id(api, id) } else { - retrieve_url_reg(&api) + retrieve_url_reg(api) } } fn retrieve_url_reg(api: &models::api::API) -> String { + /* let mut url: String = String::from(&api.url); url += &String::from("/"); url += &String::from("api/"); @@ -16,11 +17,14 @@ fn retrieve_url_reg(api: &models::api::API) -> String { url += &String::from("/"); url += &String::from(&api.endpoint); url += &String::from("/"); + */ + let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint); - return url; + url } fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String { + /* let mut url: String = String::from(&api.url); url += &String::from("api/"); url += &String::from(&api.version); @@ -28,6 +32,8 @@ fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String { url += &String::from(&api.endpoint); url += &String::from("/"); url += &id.to_string(); + */ + let url = format!("{}/api/{}/{}/{}", api.url, api.version, api.endpoint, id); - return url; + url } diff --git a/src/syncers/delete.rs b/src/syncers/delete.rs index a62f24b..ba94ae6 100644 --- a/src/syncers/delete.rs +++ b/src/syncers/delete.rs @@ -5,11 +5,12 @@ use reqwest; use crate::models; use crate::syncers; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Delete { pub api: models::api::API, } +/* impl Default for Delete { fn default() -> Self { Delete { @@ -17,6 +18,7 @@ impl Default for Delete { } } } +*/ impl Delete { pub async fn delete_song( @@ -41,14 +43,12 @@ impl Delete { match response.json::().await { Ok(sng) => Ok(sng), - Err(er) => Err(std::io::Error::new( - std::io::ErrorKind::Other, + Err(er) => Err(std::io::Error::other( er.to_string(), )), } } - other => Err(std::io::Error::new( - std::io::ErrorKind::Other, + other => Err(std::io::Error::other( other.to_string(), )), } diff --git a/src/syncers/download.rs b/src/syncers/download.rs index 7e92bc8..07abad8 100644 --- a/src/syncers/download.rs +++ b/src/syncers/download.rs @@ -3,10 +3,12 @@ use std::default::Default; use crate::models; use crate::syncers; +#[derive(Default)] pub struct Download { pub api: models::api::API, } +/* impl Default for Download { fn default() -> Self { Download { @@ -14,6 +16,7 @@ impl Default for Download { } } } +*/ #[derive(Debug)] pub enum MyError { @@ -31,7 +34,7 @@ impl Download { let url = syncers::common::retrieve_url(&self.api, true, &song.id); let access_token = token.bearer_token(); - println!("Url: {:?}", url); + println!("Url: {url:?}"); let client = reqwest::Client::builder().build().unwrap(); @@ -46,22 +49,22 @@ impl Download { let data = rep.text(); match data.await { Ok(e) => { - return Ok(e); + Ok(e) } Err(er) => { - return Err(MyError::Other(er.to_string())); + Err(MyError::Other(er.to_string())) } } } reqwest::StatusCode::UNAUTHORIZED => { - return Err(MyError::Other(String::from("Need to grab a new token"))); + Err(MyError::Other(String::from("Need to grab a new token"))) } other => { - return Err(MyError::Other(other.to_string())); + Err(MyError::Other(other.to_string())) } }, Err(er) => { - return Err(MyError::Request(er)); + Err(MyError::Request(er)) } } } diff --git a/src/syncers/retrieve_records.rs b/src/syncers/retrieve_records.rs index f018337..5cf4fed 100644 --- a/src/syncers/retrieve_records.rs +++ b/src/syncers/retrieve_records.rs @@ -4,10 +4,12 @@ use std::io::Error; use crate::models; use crate::syncers; +#[derive(Default)] pub struct RetrieveRecords { pub api: models::api::API, } +/* impl Default for RetrieveRecords { fn default() -> Self { RetrieveRecords { @@ -15,6 +17,7 @@ impl Default for RetrieveRecords { } } } +*/ impl RetrieveRecords { pub async fn get_all_songs( @@ -39,24 +42,21 @@ impl RetrieveRecords { match response.json::>().await { Ok(parsed) => Ok(parsed), Err(err) => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + Err(std::io::Error::other( err.to_string(), - )); + )) } } } reqwest::StatusCode::UNAUTHORIZED => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + Err(std::io::Error::other( "Need to grab a new token", - )); + )) } other => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + Err(std::io::Error::other( other.to_string(), - )); + )) } } } diff --git a/src/syncers/upload.rs b/src/syncers/upload.rs index f4a6e7d..4bd759a 100644 --- a/src/syncers/upload.rs +++ b/src/syncers/upload.rs @@ -6,10 +6,12 @@ use reqwest; use crate::models; use crate::syncers; +#[derive(Default)] pub struct Upload { pub api: models::api::API, } +/* impl Default for Upload { fn default() -> Self { Upload { @@ -17,6 +19,7 @@ impl Default for Upload { } } } +*/ impl Upload { pub async fn upload_song_with_metadata( @@ -33,8 +36,8 @@ impl Upload { println!("Url is empty"); } - println!("Url: {}", url); - println!("Token: {}", access_token); + println!("Url: {url}"); + println!("Token: {access_token}"); println!("Path: {:?}", song.song_path()); let mut headers = reqwest::header::HeaderMap::new(); @@ -44,7 +47,7 @@ impl Upload { ); headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*")); - let form = self.init_form(&song, &cover); + let form = self.init_form(song, cover); let client = reqwest::Client::builder().build().unwrap(); match client .post(url) @@ -54,10 +57,10 @@ impl Upload { .await { Ok(r) => { - return Ok(r); + Ok(r) } Err(err) => { - return Err(err); + Err(err) } } } @@ -67,25 +70,24 @@ impl Upload { song: &icarus_models::song::Song, cover: &icarus_models::coverart::CoverArt, ) -> reqwest::multipart::Form { - let songpath = match song.song_path() { - Ok(s) => s, - Err(_) => String::new(), - }; + let songpath = song.song_path().unwrap_or_default(); let coverpath = cover.path.clone(); - println!("Cover path: {:?}", coverpath); - let song_detail = match song.to_metadata_json(true) { + println!("Cover path: {coverpath:?}"); + let song_detail = song.to_metadata_json(true).unwrap_or_default(); + /*{ Ok(s) => s, Err(_) => String::new(), }; + */ - println!("\n{}\n", song_detail); + println!("\n{song_detail}\n"); let mut song_filename = String::from("audio"); song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION; let mut cover_filename = String::from("cover"); cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION; - let form = reqwest::multipart::Form::new() + reqwest::multipart::Form::new() .part( "file", reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap()) @@ -96,15 +98,11 @@ impl Upload { reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap()) .file_name(cover_filename), ) - .text("metadata", song_detail); - - return form; + .text("metadata", song_detail) } - pub fn set_api(&mut self, host: &String) { - let mut api = models::api::API::default(); - api.url = host.clone(); - api.version = String::from("v1"); + pub fn set_api(&mut self, host: &str) { + let api = models::api::API { url: host.to_owned(), version: String::from("v1"), endpoint: String::new() }; self.api = api; } } diff --git a/src/utilities/checks.rs b/src/utilities/checks.rs index 76f69a5..e3d53a5 100644 --- a/src/utilities/checks.rs +++ b/src/utilities/checks.rs @@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize}; pub struct Checks {} impl Checks { - pub fn _is_numeric(text: &String) -> bool { + pub fn _is_numeric(text: &str) -> bool { text.parse::().is_ok() } - pub fn _index_of_item_in_container(container: &String, item: &char, func: F) -> i32 + pub fn _index_of_item_in_container(container: &str, item: &char, func: F) -> i32 where F: Fn(&char, &char) -> bool, { diff --git a/src/utilities/string.rs b/src/utilities/string.rs index a5e089c..41e42ed 100644 --- a/src/utilities/string.rs +++ b/src/utilities/string.rs @@ -1,8 +1,7 @@ pub fn o_to_string(val: &std::ffi::OsString) -> Result { match val.clone().into_string() { Ok(value) => Ok(value), - Err(_) => Err(std::io::Error::new( - std::io::ErrorKind::Other, + Err(_) => Err(std::io::Error::other( String::from("Error"), )), }