aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-09-29 16:13:01 +0200
committeracdenisSK <[email protected]>2017-09-29 16:13:01 +0200
commitd90b90c7f3d8a368acbab46150f199866562229a (patch)
tree42b9a5c2a061ba662fef19277d2711c60b8c6570 /src/framework
parentFix User::tag and CurrentUser::tag discrim output (diff)
downloadserenity-d90b90c7f3d8a368acbab46150f199866562229a.tar.xz
serenity-d90b90c7f3d8a368acbab46150f199866562229a.zip
Change the way users' command handlers are stored as
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/command.rs20
-rw-r--r--src/framework/standard/create_command.rs18
-rw-r--r--src/framework/standard/create_group.rs8
-rw-r--r--src/framework/standard/mod.rs10
4 files changed, 23 insertions, 33 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index 1415d9b..96d4efd 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -9,12 +9,9 @@ pub type Check = Fn(&mut Context, &Message, &mut Args, &Arc<Command>) -> bool
+ Send
+ Sync
+ 'static;
-pub type Exec = Fn(&mut Context, &Message, Args) -> Result<(), Error> + Send + Sync + 'static;
-pub type Help = Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args)
- -> Result<(), Error>
- + Send
- + Sync
- + 'static;
+pub type Exec = fn(&mut Context, &Message, Args) -> Result<(), Error>;
+pub type Help = fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args)
+ -> Result<(), Error>;
pub type BeforeHook = Fn(&mut Context, &Message, &str) -> bool + Send + Sync + 'static;
pub type AfterHook = Fn(&mut Context, &Message, &str, Result<(), Error>) + Send + Sync + 'static;
pub(crate) type InternalCommand = Arc<Command>;
@@ -39,8 +36,8 @@ impl<D: fmt::Display> From<D> for Error {
/// your commands.
pub enum CommandType {
StringResponse(String),
- Basic(Box<Exec>),
- WithCommands(Box<Help>),
+ Basic(Exec),
+ WithCommands(Help),
}
pub struct CommandGroup {
@@ -91,10 +88,9 @@ pub struct Command {
}
impl Command {
- pub fn new<F>(f: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), Error> + Send + Sync + 'static {
+ pub fn new(f: fn(&mut Context, &Message, Args) -> Result<(), Error>) -> Self {
Command {
- exec: CommandType::Basic(Box::new(f)),
+ exec: CommandType::Basic(f),
..Command::default()
}
}
@@ -105,7 +101,7 @@ impl Default for Command {
Command {
aliases: Vec::new(),
checks: Vec::default(),
- exec: CommandType::Basic(Box::new(|_, _, _| Ok(()))),
+ exec: CommandType::Basic(|_, _, _| Ok(())),
desc: None,
usage: None,
example: None,
diff --git a/src/framework/standard/create_command.rs b/src/framework/standard/create_command.rs
index 423d982..99798ca 100644
--- a/src/framework/standard/create_command.rs
+++ b/src/framework/standard/create_command.rs
@@ -106,9 +106,8 @@ impl CreateCommand {
/// See [`exec_str`] if you _only_ need to return a string on command use.
///
/// [`exec_str`]: #method.exec_str
- pub fn exec<F>(mut self, func: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), CommandError> + Send + Sync + 'static {
- self.0.exec = CommandType::Basic(Box::new(func));
+ pub fn exec(mut self, func: fn(&mut Context, &Message, Args) -> Result<(), CommandError>) -> Self {
+ self.0.exec = CommandType::Basic(func);
self
}
@@ -117,14 +116,11 @@ impl CreateCommand {
/// the internal HashMap of commands, used specifically for creating a help
/// command.
///
- /// You can return `Err(Custom(string))` if there's an error.
- pub fn exec_help<F>(mut self, f: F) -> Self
- where F: Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args)
- -> Result<(), CommandError>
- + Send
- + Sync
- + 'static {
- self.0.exec = CommandType::WithCommands(Box::new(f));
+ /// You can return `Err(From::from(string))` if there's an error.
+ pub fn exec_help(mut self, f:
+ fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args)
+ -> Result<(), CommandError>) -> Self {
+ self.0.exec = CommandType::WithCommands(f);
self
}
diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs
index 699e56f..15db5a4 100644
--- a/src/framework/standard/create_group.rs
+++ b/src/framework/standard/create_group.rs
@@ -70,14 +70,14 @@ impl CreateGroup {
}
/// Adds a command to group with simplified API.
- /// You can return Err(string) if there's an error.
- pub fn on<F>(mut self, command_name: &str, f: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), CommandError> + Send + Sync + 'static {
+ /// You can return Err(From::from(string)) if there's an error.
+ pub fn on(mut self, name: &str,
+ f: fn(&mut Context, &Message, Args) -> Result<(), CommandError>) -> Self {
let cmd = Arc::new(Command::new(f));
self.0
.commands
- .insert(command_name.to_owned(), CommandOrAlias::Command(cmd));
+ .insert(name.to_string(), CommandOrAlias::Command(cmd));
self
}
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index ffee5d2..1f4a33e 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -596,20 +596,18 @@ impl StandardFramework {
/// });
/// # }
/// ```
- pub fn on<F, S>(mut self, command_name: S, f: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), CommandError> + Send + Sync + 'static,
- S: Into<String> {
+ pub fn on(mut self, name: &str,
+ f: fn(&mut Context, &Message, Args)
+ -> Result<(), CommandError>) -> Self {
{
let ungrouped = self.groups
.entry("Ungrouped".to_owned())
.or_insert_with(|| Arc::new(CommandGroup::default()));
if let Some(ref mut group) = Arc::get_mut(ungrouped) {
- let name = command_name.into();
-
group
.commands
- .insert(name, CommandOrAlias::Command(Arc::new(Command::new(f))));
+ .insert(name.to_string(), CommandOrAlias::Command(Arc::new(Command::new(f))));
}
}