From 34de7618582fc7ea75830c36609a4d604e8c2f59 Mon Sep 17 00:00:00 2001 From: kageru Date: Thu, 31 Oct 2019 11:45:16 +0100 Subject: [PATCH] clippy --- src/commands/apt.rs | 4 ++-- src/commands/mod.rs | 11 +++++------ src/commands/nix.rs | 2 +- src/commands/pacman.rs | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/commands/apt.rs b/src/commands/apt.rs index 2cb94b4..564b0f8 100644 --- a/src/commands/apt.rs +++ b/src/commands/apt.rs @@ -9,7 +9,7 @@ pub fn query_apt(ctx: Context, msg: Message, args: Vec<&str>) { &format!("https://sources.debian.org/api/src/{}/", &query), |_e| EMPTY_RESULT, ); - if response.versions.len() == 0 { + if response.versions.is_empty() { send(msg.channel_id, "No results", &ctx); return; } @@ -24,7 +24,7 @@ fn convert_versions(res: Response) -> Vec { packages.push(Package { area: version.area.clone(), name: res.package.clone(), - suite: suite, + suite, version: version.version.clone(), }); } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 97c631e..78ac2ba 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -24,14 +24,13 @@ impl EventHandler for Handler { if msg.content.starts_with(PREFIX) { if let Some(command) = COMMANDS .iter() - .filter(|&c| msg.content.starts_with(&c.trigger)) - .next() + .find(|&c| msg.content.starts_with(&c.trigger)) { let content = msg.content.clone(); let mut args = content.split_whitespace().collect::>(); // the prefix + trigger args.remove(0); - if args.len() == 0 { + if args.is_empty() { send( msg.channel_id, "Error: expected at least 1 additional argument", @@ -72,13 +71,13 @@ pub fn send(target: ChannelId, message: &str, ctx: &Context) { } } -pub fn respond_with_results(target: ChannelId, results: &Vec, ctx: &Context) { +pub fn respond_with_results(target: ChannelId, results: &[T], ctx: &Context) { send( target, &format!( "```{}```", results - .into_iter() + .iter() .take(5) .map(|p| format!("{}\n", p)) .collect::() @@ -88,7 +87,7 @@ pub fn respond_with_results(target: ChannelId, results: &Vec } pub fn search(url: &str, fallback: impl Fn(reqwest::Error) -> T) -> T { - return search_inner(url).unwrap_or_else(fallback); + search_inner(url).unwrap_or_else(fallback) } fn search_inner(url: &str) -> Result { diff --git a/src/commands/nix.rs b/src/commands/nix.rs index b895787..0e0fae1 100644 --- a/src/commands/nix.rs +++ b/src/commands/nix.rs @@ -10,7 +10,7 @@ pub fn query_nix(ctx: Context, msg: Message, args: Vec<&str>) { // we know for sure that there’s at least one element here let query = args[0]; match NIX_PACKAGES.packages.get(query) { - Some(result) => respond_with_results(msg.channel_id, &vec![result], &ctx), + Some(result) => respond_with_results(msg.channel_id, &[result], &ctx), None => send(msg.channel_id, "No results", &ctx), } } diff --git a/src/commands/pacman.rs b/src/commands/pacman.rs index 0d9a458..8f0222a 100644 --- a/src/commands/pacman.rs +++ b/src/commands/pacman.rs @@ -14,7 +14,7 @@ pub fn query_pacman(ctx: Context, msg: Message, args: Vec<&str>) { |_e| EMPTY_RESULT, ); // this is 1 for most packages and 2 if there’s a second version in testing - if response.results.len() != 0 { + if response.results.is_empty() { respond_with_results(msg.channel_id, &response.results, &ctx); return; } @@ -27,7 +27,7 @@ pub fn query_pacman(ctx: Context, msg: Message, args: Vec<&str>) { ), |_e| EMPTY_RESULT, ); - if response.results.len() == 0 { + if response.results.is_empty() { send(msg.channel_id, "No results", &ctx); return; }