From f5e070cdf6628a5ebd981d373929802317104e24 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 09:56:42 +0200 Subject: clippy --fix --- src/db.rs | 62 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 49db2fd..6a3c9af 100644 --- a/src/db.rs +++ b/src/db.rs @@ -52,7 +52,7 @@ pub fn mods_get_all_ids( /// ///Will return `MLError` when no mod id is found pub fn mods_get_id(data: &str, slug: &str) -> MLE { - let data = format!("{}/data.db", data); + let data = format!("{data}/data.db"); let connection = Connection::open(data)?; let mut mod_id = String::new(); @@ -157,14 +157,14 @@ pub fn mods_get_versions( for (i, id) in mods.iter().enumerate() { let mut or = " OR"; if i == mods.len() - 1 { - or = "" + or = ""; }; - wherestr = format!("{} id = '{}'{}", wherestr, id, or); + wherestr = format!("{wherestr} id = '{id}'{or}"); } let mut versionmaps: Vec = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT id, versions, title FROM mods {}", wherestr).as_str(), + format!("SELECT id, versions, title FROM mods {wherestr}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -179,7 +179,7 @@ pub fn mods_get_versions( versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]), - }) + }); } match versionmaps.is_empty() { @@ -208,8 +208,7 @@ pub fn userlist_insert( connection.execute( format!( - "INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", - list_id + "INSERT INTO {list_id} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)" ) .as_str(), [ @@ -230,17 +229,17 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE> { let mut mod_ids: Vec = Vec::new(); let mut stmt = connection - .prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; + .prepare(format!("SELECT mod_id FROM {list_id}").as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { - mod_ids.push(id?) + mod_ids.push(id?); } match mod_ids.is_empty() { true => Err(MLError::new( ErrorType::DBError, - &format!("NO_MODS_USERLIST{}", list_id), + &format!("NO_MODS_USERLIST{list_id}"), )), false => Ok(mod_ids), } @@ -251,7 +250,7 @@ pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let connection = Connection::open(data)?; connection.execute( - format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), + format!("DELETE FROM {list_id} WHERE mod_id = ?").as_str(), [mod_id], )?; Ok(()) @@ -268,8 +267,7 @@ pub fn userlist_get_applicable_versions( let mut version: String = String::new(); let mut stmt = connection.prepare( format!( - "SELECT applicable_versions FROM {} WHERE mod_id = ?", - list_id + "SELECT applicable_versions FROM {list_id} WHERE mod_id = ?" ) .as_str(), )?; @@ -295,7 +293,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( let mut versions: Vec<(String, String)> = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str(), + format!("SELECT mod_id, applicable_versions FROM {list_id}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -306,7 +304,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( for ver in id_iter { let out = ver?; - versions.push((out[0].to_owned(), out[1].to_owned())); + versions.push((out[0].clone(), out[1].clone())); } if versions.is_empty() { @@ -326,7 +324,7 @@ pub fn userlist_get_current_version( let mut version: String = String::new(); let mut stmt = connection.prepare( - format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id) + format!("SELECT current_version FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -351,7 +349,7 @@ pub fn userlist_get_all_current_version_ids( let mut versions: Vec = Vec::new(); let mut stmt = connection - .prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; + .prepare(format!("SELECT current_version FROM {list_id}").as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { @@ -374,7 +372,7 @@ pub fn userlist_get_all_current_versions_with_mods( let mut versions: Vec<(String, String)> = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT mod_id, current_version FROM {}", list_id).as_str(), + format!("SELECT mod_id, current_version FROM {list_id}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -385,7 +383,7 @@ pub fn userlist_get_all_current_versions_with_mods( for ver in id_iter { let out = ver?; - versions.push((out[0].to_owned(), out[1].to_owned())); + versions.push((out[0].clone(), out[1].clone())); } if versions.is_empty() { @@ -408,7 +406,7 @@ pub fn userlist_get_set_version( let mut set_version: bool = false; let mut stmt = connection.prepare( - format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id) + format!("SELECT set_version FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -432,7 +430,7 @@ pub fn userlist_change_versions( let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - connection.execute(format!("UPDATE {} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4", list_id).as_str(), [current_version, versions, link, mod_id])?; + connection.execute(format!("UPDATE {list_id} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4").as_str(), [current_version, versions, link, mod_id])?; Ok(()) } @@ -453,14 +451,13 @@ pub fn userlist_add_disabled_versions( let disabled_versions = match currently_disabled_versions == "NONE" { true => disabled_version, false => { - format!("{}|{}", currently_disabled_versions, disabled_version) + format!("{currently_disabled_versions}|{disabled_version}") } }; connection.execute( format!( - "UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", - list_id + "UPDATE {list_id} SET disabled_versions = ?1 WHERE mod_id = ?2" ) .as_str(), [disabled_versions, mod_id], @@ -478,7 +475,7 @@ pub fn userlist_get_disabled_versions( let mut version: String = String::new(); let mut stmt = connection.prepare( - format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id) + format!("SELECT disabled_versions FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -503,13 +500,13 @@ pub fn userlist_get_all_downloads( let mut links: Vec = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT current_download FROM {}", list_id).as_str(), + format!("SELECT current_download FROM {list_id}").as_str(), )?; let link_iter = stmt.query_map([], |row| row.get::(0))?; for link in link_iter { let l = link?; - links.push(l) + links.push(l); } if links.is_empty() { @@ -538,7 +535,7 @@ pub fn lists_insert( "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id, mc_version, &mod_loader.to_string(), download_folder], )?; - connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; + connection.execute(format!("CREATE TABLE {id}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {id}_PK PRIMARY KEY (mod_id) )").as_str(), [])?; Ok(()) } @@ -548,7 +545,7 @@ pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> { let connection = Connection::open(data)?; connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; - connection.execute(format!("DROP TABLE {}", id).as_str(), [])?; + connection.execute(format!("DROP TABLE {id}").as_str(), [])?; Ok(()) } @@ -611,7 +608,7 @@ pub fn lists_get_all_ids(config: &Cfg) -> MLE> { let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { - list_ids.push(id?) + list_ids.push(id?); } match list_ids.is_empty() { @@ -664,8 +661,7 @@ pub fn s_userlist_update_download( connection.execute( format!( - "UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", - list_id + "UPDATE {list_id} SET current_download = ?1 WHERE mod_id = ?2" ) .as_str(), [link, mod_id], @@ -734,7 +730,7 @@ pub fn s_insert_column( let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); + let mut sql = format!("ALTER TABLE {table} ADD '{column}' {c_type}"); if default.is_some() { sql = format!("{} DEFAULT {}", sql, default.unwrap()); -- cgit v1.2.3