From e7fa36f1d291bb85b795b36af71baac0eb83fa15 Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Tue, 2 Apr 2024 10:48:55 +0200 Subject: [PATCH] Fix clippy warnings - `clippy::default_trait_access` - `clippy::implicit_clone` - `clippy::match_wildcard_for_single_variants` - `clippy::multiple_bound_locations` - `clippy::redundant_closure_for_method_calls` - `clippy::single_match_else` - `clippy::uninlined_format_args` - `clippy::wildcard_imports` - `unused_imports` --- src/bin/modiom/commands/download.rs | 3 +-- src/bin/modiom/commands/expr.rs | 8 ++++---- src/bin/modiom/commands/info.rs | 12 ++++++------ src/bin/modiom/commands/install.rs | 6 +++--- src/bin/modiom/commands/login.rs | 28 ++++++++++++---------------- src/bin/modiom/commands/mod.rs | 2 -- src/bin/modiom/commands/search.rs | 5 ++--- src/bin/modiom/commands/subs.rs | 5 ++--- src/bin/modiom/commands/upload.rs | 5 ++--- src/bin/modiom/main.rs | 5 +---- src/config.rs | 4 ++-- src/utils.rs | 6 +++--- 12 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/bin/modiom/commands/download.rs b/src/bin/modiom/commands/download.rs index 143c0e5..8dbc0a1 100644 --- a/src/bin/modiom/commands/download.rs +++ b/src/bin/modiom/commands/download.rs @@ -5,7 +5,6 @@ use tokio::runtime::Runtime; use modio::filter::prelude::*; use modio::types::id::{GameId, ModId}; -use modiom::config::Config; use crate::command_prelude::*; @@ -64,7 +63,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { } } for mm in missing_mods { - println!("Mod.id: {} does not exist or has no primary file. ", mm); + println!("Mod.id: {mm} does not exist or has no primary file."); } Ok(()) diff --git a/src/bin/modiom/commands/expr.rs b/src/bin/modiom/commands/expr.rs index 3f33c21..d0160c4 100644 --- a/src/bin/modiom/commands/expr.rs +++ b/src/bin/modiom/commands/expr.rs @@ -125,7 +125,7 @@ impl fmt::Display for Condition { mod parser { use std::str::FromStr; - use super::*; + use super::{Condition, Expr, Literal, Operator}; use nom::branch::alt; use nom::bytes::complete::{tag, tag_no_case, take_until, take_while}; @@ -323,7 +323,7 @@ mod parser { let msg = match e { nom::Err::Error(Error { input, .. }) | nom::Err::Failure(Error { input, .. }) => { - format!("failed to parse {:?}", input) + format!("failed to parse {input:?}") } nom::Err::Incomplete(_) => String::from("failed to parse expression"), }; @@ -338,8 +338,8 @@ mod parser { Ok((_, (None, right))) => { let op = match right { Condition::Literal(Literal::String(ref s)) if s.contains('*') => Operator::Like, + Condition::Literal(_) => Operator::Equals, Condition::LiteralList(_) => Operator::In, - _ => Operator::Equals, }; (op, right) } @@ -347,7 +347,7 @@ mod parser { let msg = match e { nom::Err::Error(Error { input, .. }) | nom::Err::Failure(Error { input, .. }) => { - format!("failed to parse {:?}", input) + format!("failed to parse {input:?}") } nom::Err::Incomplete(_) => String::from("failed to parse expression"), }; diff --git a/src/bin/modiom/commands/info.rs b/src/bin/modiom/commands/info.rs index 379d365..7b5b71a 100644 --- a/src/bin/modiom/commands/info.rs +++ b/src/bin/modiom/commands/info.rs @@ -3,8 +3,8 @@ use prettytable::format; use textwrap::fill; use tokio::runtime::Runtime; +use modio::filter::Filter; use modio::types::id::{GameId, ModId}; -use modiom::config::Config; use crate::command_prelude::*; @@ -40,7 +40,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { let files = async { if args.get_flag("files") { - let f = Default::default(); + let f = Filter::default(); modref.files().search(f).first_page().map_ok(Some).await } else { Ok(None) @@ -79,8 +79,8 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { [b -> "Summary", fill(&m.summary, 60)], [b -> "Profile", m.profile_url], [b -> "Homepage", m.homepage_url.map(|u| u.to_string()).unwrap_or_default()], - [b -> "Tags", format!("[{}]", tags)], - [b -> "Dependencies", format!("{:?}", deps)] + [b -> "Tags", format!("[{tags}]")], + [b -> "Dependencies", format!("{deps:?}")] ); let mut primary = None; mt.set_format(*format::consts::FORMAT_CLEAN); @@ -131,7 +131,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { for file in files { let suffix = if primary == Some(file.id) { "*" } else { "" }; ft.add_row(row![ - format!("{}{}", file.id, suffix), + format!("{}{suffix}", file.id), file.filename, file.version.unwrap_or_default(), file.download.binary_url @@ -140,7 +140,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { ft.printstd(); } } - Err(e) => println!("{}", e), + Err(e) => println!("{e}"), }; Ok(()) } diff --git a/src/bin/modiom/commands/install.rs b/src/bin/modiom/commands/install.rs index 1113400..a915099 100644 --- a/src/bin/modiom/commands/install.rs +++ b/src/bin/modiom/commands/install.rs @@ -33,7 +33,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { if let Some(game) = first { game.id } else { - return Err(format!("no matching game named `{}` found", id).into()); + return Err(format!("no matching game named `{id}` found").into()); } } }; @@ -43,11 +43,11 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { let not_found: Box = match m.id() { Identifier::Id(id) => { filter = Id::eq(id); - format!("mod with id `{}` not found", id).into() + format!("mod with id `{id}` not found").into() } Identifier::NameId(id) => { filter = NameId::eq(id); - format!("mod with name-id `{}` not found", id).into() + format!("mod with name-id `{id}` not found").into() } }; tasks.push(async { diff --git a/src/bin/modiom/commands/login.rs b/src/bin/modiom/commands/login.rs index 2318689..8cee130 100644 --- a/src/bin/modiom/commands/login.rs +++ b/src/bin/modiom/commands/login.rs @@ -1,12 +1,9 @@ use std::io::{self, BufRead, Write}; -use clap::Arg; use modio::auth::Credentials; use modio::Modio; use tokio::runtime::Runtime; -use modiom::config::Config; - use crate::command_prelude::*; pub fn cli() -> Command { @@ -22,18 +19,17 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { let token = match (api_key, token) { (Some(api_key), Some(token)) => Credentials::with_token(api_key, token), (api_key, _) => { - let api_key = match api_key { - Some(api_key) => api_key.into(), - None => { - let url = if args.is_test_env() { - "https://test.mod.io/apikey" - } else { - "https://mod.io/apikey" - }; - println!("Please visit {} and paste the API key below", url); + let api_key = if let Some(api_key) = api_key { + api_key.into() + } else { + let url = if args.is_test_env() { + "https://test.mod.io/apikey" + } else { + "https://mod.io/apikey" + }; + println!("Please visit {url} and paste the API key below"); - prompt("Enter api key: ")? - } + prompt("Enter api key: ")? }; let email = prompt("Enter email: ")?; @@ -47,7 +43,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { let code = prompt("Enter security code: ")?; match rt.block_on(m.auth().security_code(&code)) { Ok(token) => break token, - Err(err) => println!("{}", err), + Err(err) => println!("{err}"), }; } } @@ -70,7 +66,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { } fn prompt(prompt: &str) -> io::Result { - print!("{}", prompt); + print!("{prompt}"); io::stdout().flush()?; let mut buf = String::new(); let input = io::stdin(); diff --git a/src/bin/modiom/commands/mod.rs b/src/bin/modiom/commands/mod.rs index 7556273..e770f15 100644 --- a/src/bin/modiom/commands/mod.rs +++ b/src/bin/modiom/commands/mod.rs @@ -1,5 +1,3 @@ -use modiom::config::Config; - use crate::command_prelude::*; pub fn builtin() -> Vec { diff --git a/src/bin/modiom/commands/search.rs b/src/bin/modiom/commands/search.rs index 025e657..50302fd 100644 --- a/src/bin/modiom/commands/search.rs +++ b/src/bin/modiom/commands/search.rs @@ -4,7 +4,6 @@ use tokio::runtime::Runtime; use modio::filter::custom_filter; use modio::filter::prelude::*; use modio::types::id::GameId; -use modiom::config::Config; use crate::command_prelude::*; use crate::commands::expr; @@ -72,7 +71,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { f = f.and(custom_filter(e.property, e.op.into(), e.right.into_value())); } if let Some(ft) = args.get_string("ft") { - filter.add_row(row![format!("fulltext = {:?}", ft)]); + filter.add_row(row![format!("fulltext = {ft:?}")]); f = f.and(Fulltext::eq(ft)); } if !filter.is_empty() { @@ -104,7 +103,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { f = f.and(custom_filter(e.property, e.op.into(), e.right.into_value())); } if let Some(ft) = args.get_string("ft") { - filter.add_row(row![format!("fulltext = {:?}", ft)]); + filter.add_row(row![format!("fulltext = {ft:?}")]); f = f.and(Fulltext::eq(ft)); } if !filter.is_empty() { diff --git a/src/bin/modiom/commands/subs.rs b/src/bin/modiom/commands/subs.rs index 1ee19ed..e349166 100644 --- a/src/bin/modiom/commands/subs.rs +++ b/src/bin/modiom/commands/subs.rs @@ -7,8 +7,7 @@ use tokio::runtime::Runtime; use modio::filter::prelude::*; use modio::types::id; use modio::types::mods::Mod; -use modio::user::filters::subscriptions::*; -use modiom::config::Config; +use modio::user::filters::subscriptions::GameId; use crate::command_prelude::*; @@ -78,7 +77,7 @@ fn list_subs(config: &Config, args: &ArgMatches) -> CliResult { let filter = if let Some(game_id) = game_id { GameId::eq(game_id) } else { - Default::default() + Filter::default() }; let task = async { diff --git a/src/bin/modiom/commands/upload.rs b/src/bin/modiom/commands/upload.rs index e31915e..9a1c935 100644 --- a/src/bin/modiom/commands/upload.rs +++ b/src/bin/modiom/commands/upload.rs @@ -9,7 +9,6 @@ use tokio_util::io::ReaderStream; use modio::files::AddFileOptions; use modio::types::id::{GameId, ModId}; -use modiom::config::Config; use modiom::md5::Md5; use crate::command_prelude::*; @@ -79,7 +78,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { } else { src.file_name() .and_then(|n| n.to_str()) - .map(|n| n.to_string()) + .map(ToString::to_string) .ok_or("Failed to get the filename")? .into() }; @@ -139,7 +138,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult { ft.set_format(*format::consts::FORMAT_CLEAN); ft.printstd(); } - Err(e) => println!("{}", e), + Err(e) => println!("{e}"), } Ok(()) } diff --git a/src/bin/modiom/main.rs b/src/bin/modiom/main.rs index 936f8c0..d25aa53 100644 --- a/src/bin/modiom/main.rs +++ b/src/bin/modiom/main.rs @@ -1,6 +1,3 @@ -use modiom::config::Config; -use modiom::CliResult; - mod command_prelude; mod commands; @@ -24,7 +21,7 @@ fn main() -> CliResult { match commands::exec(&config, &args) { Err(e) => { - eprintln!("{}", e); + eprintln!("{e}"); std::process::exit(1); } Ok(()) => Ok(()), diff --git a/src/config.rs b/src/config.rs index 258bb70..a493f62 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,9 +71,9 @@ impl Config { let config = self.load_config()?; if let Some(creds) = config.hosts.get(self.host()) { Ok(Some(Credentials { - api_key: creds.api_key.to_owned(), + api_key: creds.api_key.clone(), token: Some(modio::auth::Token { - value: creds.token.to_owned(), + value: creds.token.clone(), expired_at: None, }), })) diff --git a/src/utils.rs b/src/utils.rs index 438ca54..7461b16 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -27,10 +27,10 @@ pub fn read(path: &Path) -> io::Result { Ok(ret) } -pub fn copy(reader: &mut R, writer: &mut W) -> io::Result +pub fn copy(reader: &mut R, writer: &mut W) -> io::Result where - R: Read, - W: Write, + R: Read + ?Sized, + W: Write + ?Sized, { let mut buf = vec![0; 512 * 512]; let mut written = 0;