aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-16 13:24:09 -0800
committerZeyla Hellyer <[email protected]>2017-12-16 13:24:09 -0800
commit9b53582f5e5e9650abda4106124e7f9f4e78a90c (patch)
tree88bd56a75b1d110ea049abbaea88bb6e8a83dac3 /src/framework
parentFix compilation of examples (diff)
downloadserenity-9b53582f5e5e9650abda4106124e7f9f4e78a90c.tar.xz
serenity-9b53582f5e5e9650abda4106124e7f9f4e78a90c.zip
Fix most clippy lints, take more refeernces
Fix clippy lints and subsequently accept references for more function parameters.
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/args.rs21
-rw-r--r--src/framework/standard/command.rs8
-rw-r--r--src/framework/standard/create_help_command.rs3
-rw-r--r--src/framework/standard/help_commands.rs33
-rw-r--r--src/framework/standard/mod.rs4
5 files changed, 38 insertions, 31 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs
index e9c6365..f18b012 100644
--- a/src/framework/standard/args.rs
+++ b/src/framework/standard/args.rs
@@ -55,7 +55,7 @@ fn second_quote_occurence(s: &str) -> Option<usize> {
s.chars().enumerate().filter(|&(_, c)| c == '"').nth(1).map(|(pos, _)| pos)
}
-fn parse_quotes<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err>
+fn parse_quotes<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err>
where T::Err: StdError {
// Fall back to `parse` if there're no quotes at the start.
@@ -63,28 +63,28 @@ fn parse_quotes<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err
return parse::<T>(s, delimiter);
}
- let mut pos = second_quote_occurence(&s).unwrap_or(s.len());
+ let mut pos = second_quote_occurence(s).unwrap_or_else(|| s.len());
let res = (&s[1..pos]).parse::<T>().map_err(Error::Parse);
// +1 is for the quote
if pos < s.len() {
pos += 1;
}
-
+
s.drain(..pos);
res
}
-fn parse<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err>
+fn parse<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err>
where T::Err: StdError {
- let mut pos = s.find(delimiter).unwrap_or(s.len());
+ let mut pos = s.find(delimiter).unwrap_or_else(|| s.len());
let res = (&s[..pos]).parse::<T>().map_err(Error::Parse);
// +1 is for the delimiter
if pos < s.len() {
pos += 1;
}
-
+
s.drain(..pos);
res
}
@@ -100,7 +100,7 @@ pub struct Args {
}
impl Args {
- pub fn new(message: &str, possible_delimiters: Vec<String>) -> Self {
+ pub fn new(message: &str, possible_delimiters: &[String]) -> Self {
let delimiter = possible_delimiters
.iter()
.find(|&d| message.contains(d))
@@ -145,7 +145,10 @@ impl Args {
return Err(Error::Eos);
}
- let pos = self.message.find(&self.delimiter).unwrap_or(self.message.len());
+ let pos = self
+ .message
+ .find(&self.delimiter)
+ .unwrap_or_else(|| self.message.len());
fn parse_then_remove(msg: &mut String, pos: usize) -> &str {
struct ParseThenRemove<'a>(&'a mut String, usize);
@@ -355,7 +358,7 @@ impl Args {
}
// TODO: Make this efficient
-
+
let pos = self.message
.split(&self.delimiter)
.position(|e| e.parse::<T>().is_ok());
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index be0196c..5138596 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -13,7 +13,7 @@ pub type Check = Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool
+ Sync
+ 'static;
-pub type HelpFunction = fn(&mut Context, &Message, &HelpOptions, HashMap<String, Arc<CommandGroup>>, Args)
+pub type HelpFunction = fn(&mut Context, &Message, &HelpOptions, HashMap<String, Arc<CommandGroup>>, &Args)
-> Result<(), Error>;
pub struct Help(pub HelpFunction, pub Arc<HelpOptions>);
@@ -25,7 +25,7 @@ impl Debug for Help {
}
impl HelpCommand for Help {
- fn execute(&self, c: &mut Context, m: &Message, ho: &HelpOptions,hm: HashMap<String, Arc<CommandGroup>>, a: Args) -> Result<(), Error> {
+ fn execute(&self, c: &mut Context, m: &Message, ho: &HelpOptions,hm: HashMap<String, Arc<CommandGroup>>, a: &Args) -> Result<(), Error> {
(self.0)(c, m, ho, hm, a)
}
}
@@ -176,7 +176,7 @@ pub struct HelpOptions {
}
pub trait HelpCommand: Send + Sync + 'static {
- fn execute(&self, &mut Context, &Message, &HelpOptions, HashMap<String, Arc<CommandGroup>>, Args) -> Result<(), Error>;
+ fn execute(&self, &mut Context, &Message, &HelpOptions, HashMap<String, Arc<CommandGroup>>, &Args) -> Result<(), Error>;
fn options(&self) -> Arc<CommandOptions> {
Arc::clone(&DEFAULT_OPTIONS)
@@ -184,7 +184,7 @@ pub trait HelpCommand: Send + Sync + 'static {
}
impl HelpCommand for Arc<HelpCommand> {
- fn execute(&self, c: &mut Context, m: &Message, ho: &HelpOptions, hm: HashMap<String, Arc<CommandGroup>>, a: Args) -> Result<(), Error> {
+ fn execute(&self, c: &mut Context, m: &Message, ho: &HelpOptions, hm: HashMap<String, Arc<CommandGroup>>, a: &Args) -> Result<(), Error> {
(**self).execute(c, m, ho, hm, a)
}
}
diff --git a/src/framework/standard/create_help_command.rs b/src/framework/standard/create_help_command.rs
index a8e8704..7e4c338 100644
--- a/src/framework/standard/create_help_command.rs
+++ b/src/framework/standard/create_help_command.rs
@@ -173,6 +173,7 @@ impl CreateHelpCommand {
/// Finishes the creation of a help-command, returning `Help`.
/// If `Some(String)` was set as `striked_commands_tip` and the `String` is empty,
/// the creator will substitute content based on the `HelpBehaviour`-settings.
+ #[cfg_attr(feature = "cargo-clippy", allow(useless_if_let_seq))]
pub(crate) fn finish(self) -> Arc<Help> {
if self.0.striked_commands_tip == Some(String::new()) {
let mut strike_text = String::from("~~`Striked commands`~~ are unavailable because they");
@@ -210,4 +211,4 @@ impl CreateHelpCommand {
Arc::new(Help(function, Arc::new(options)))
}
-} \ No newline at end of file
+}
diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs
index 85debc4..c660209 100644
--- a/src/framework/standard/help_commands.rs
+++ b/src/framework/standard/help_commands.rs
@@ -28,6 +28,7 @@ use framework::standard::{has_correct_roles, has_correct_permissions};
use model::channel::Message;
use model::id::ChannelId;
use std::collections::HashMap;
+use std::hash::BuildHasher;
use std::sync::Arc;
use std::fmt::Write;
use super::command::{InternalCommand};
@@ -91,12 +92,13 @@ pub fn has_all_requirements(cmd: &Arc<CommandOptions>, msg: &Message) -> bool {
/// client.with_framework(StandardFramework::new()
/// .help(help_commands::with_embeds));
/// ```
-pub fn with_embeds(_: &mut Context,
- msg: &Message,
- help_options: &HelpOptions,
- groups: HashMap<String, Arc<CommandGroup>>,
- args: Args)
- -> Result<(), CommandError> {
+pub fn with_embeds<H: BuildHasher>(
+ _: &mut Context,
+ msg: &Message,
+ help_options: &HelpOptions,
+ groups: HashMap<String, Arc<CommandGroup>, H>,
+ args: &Args
+) -> Result<(), CommandError> {
if !args.is_empty() {
let name = args.full();
@@ -151,7 +153,7 @@ pub fn with_embeds(_: &mut Context,
let _ = msg.channel_id.send_message(|m| {
m.embed(|e| {
- let mut embed = e.colour(help_options.embed_success_colour.clone()).title(command_name.clone());
+ let mut embed = e.colour(help_options.embed_success_colour).title(command_name.clone());
if let Some(ref desc) = command.desc {
embed = embed.description(desc);
@@ -197,7 +199,7 @@ pub fn with_embeds(_: &mut Context,
}
}
- let error_msg = help_options.command_not_found_text.replace("{}", &name);
+ let error_msg = help_options.command_not_found_text.replace("{}", name);
error_embed(&msg.channel_id, &error_msg, help_options.embed_error_colour);
return Ok(());
@@ -304,12 +306,13 @@ pub fn with_embeds(_: &mut Context,
/// client.with_framework(StandardFramework::new()
/// .help(help_commands::plain));
/// ```
-pub fn plain(_: &mut Context,
- msg: &Message,
- help_options: &HelpOptions,
- groups: HashMap<String, Arc<CommandGroup>>,
- args: Args)
- -> Result<(), CommandError> {
+pub fn plain<H: BuildHasher>(
+ _: &mut Context,
+ msg: &Message,
+ help_options: &HelpOptions,
+ groups: HashMap<String, Arc<CommandGroup>, H>,
+ args: &Args
+) -> Result<(), CommandError> {
if !args.is_empty() {
let name = args.full();
@@ -406,7 +409,7 @@ pub fn plain(_: &mut Context,
}
let _ = msg.channel_id
- .say(&help_options.suggestion_text.replace("{}", &name));
+ .say(&help_options.suggestion_text.replace("{}", name));
return Ok(());
}
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index 576f820..02de3c0 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -973,7 +973,7 @@ impl Framework for StandardFramework {
let mut content = message.content[position..].trim();
content = content[command_length..].trim();
- Args::new(&content, self.configuration.delimiters.clone())
+ Args::new(content, &self.configuration.delimiters)
};
let before = self.before.clone();
@@ -994,7 +994,7 @@ impl Framework for StandardFramework {
}
}
- let result = (help.0)(&mut context, &message, &help.1, groups, args);
+ let result = (help.0)(&mut context, &message, &help.1, groups, &args);
if let Some(after) = after {
(after)(&mut context, &message, &built, result);