Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
- `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`
  • Loading branch information
nickelc committed Apr 2, 2024
1 parent b70682f commit e7fa36f
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 51 deletions.
3 changes: 1 addition & 2 deletions src/bin/modiom/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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(())
Expand Down
8 changes: 4 additions & 4 deletions src/bin/modiom/commands/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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"),
};
Expand All @@ -338,16 +338,16 @@ 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)
}
Err(e) => {
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"),
};
Expand Down
12 changes: 6 additions & 6 deletions src/bin/modiom/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -140,7 +140,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult {
ft.printstd();
}
}
Err(e) => println!("{}", e),
Err(e) => println!("{e}"),
};
Ok(())
}
6 changes: 3 additions & 3 deletions src/bin/modiom/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
};
Expand All @@ -43,11 +43,11 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult {
let not_found: Box<dyn std::error::Error> = 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 {
Expand Down
28 changes: 12 additions & 16 deletions src/bin/modiom/commands/login.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: ")?;

Expand All @@ -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}"),
};
}
}
Expand All @@ -70,7 +66,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult {
}

fn prompt(prompt: &str) -> io::Result<String> {
print!("{}", prompt);
print!("{prompt}");
io::stdout().flush()?;
let mut buf = String::new();
let input = io::stdin();
Expand Down
2 changes: 0 additions & 2 deletions src/bin/modiom/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use modiom::config::Config;

use crate::command_prelude::*;

pub fn builtin() -> Vec<Command> {
Expand Down
5 changes: 2 additions & 3 deletions src/bin/modiom/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions src/bin/modiom/commands/subs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/bin/modiom/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -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(())
}
5 changes: 1 addition & 4 deletions src/bin/modiom/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use modiom::config::Config;
use modiom::CliResult;

mod command_prelude;
mod commands;

Expand All @@ -24,7 +21,7 @@ fn main() -> CliResult {

match commands::exec(&config, &args) {
Err(e) => {
eprintln!("{}", e);
eprintln!("{e}");
std::process::exit(1);
}
Ok(()) => Ok(()),
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}))
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub fn read(path: &Path) -> io::Result<String> {
Ok(ret)
}

pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
pub fn copy<R, W>(reader: &mut R, writer: &mut W) -> io::Result<u64>
where
R: Read,
W: Write,
R: Read + ?Sized,
W: Write + ?Sized,
{
let mut buf = vec![0; 512 * 512];
let mut written = 0;
Expand Down

0 comments on commit e7fa36f

Please sign in to comment.