diff options
| author | acdenisSK <[email protected]> | 2017-11-20 14:55:32 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-11-20 14:55:32 +0100 |
| commit | 0aa55a2b9b757321d5b8bb9e512813aa9d0a62ca (patch) | |
| tree | a9e9243c873eadc2ae4a8c7a4733830814bf2c08 /src/framework | |
| parent | Add guild invite to readme (diff) | |
| download | serenity-0aa55a2b9b757321d5b8bb9e512813aa9d0a62ca.tar.xz serenity-0aa55a2b9b757321d5b8bb9e512813aa9d0a62ca.zip | |
Add an impl for `Fn(&mut Context, &Message, Args)`
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/command.rs | 10 | ||||
| -rw-r--r-- | src/framework/standard/create_group.rs | 13 | ||||
| -rw-r--r-- | src/framework/standard/mod.rs | 10 |
3 files changed, 13 insertions, 20 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs index 8cf4fc5..6b90479 100644 --- a/src/framework/standard/command.rs +++ b/src/framework/standard/command.rs @@ -137,11 +137,13 @@ impl Command for Box<Command> { } } -pub(crate) struct A(pub fn(&mut Context, &Message, Args) -> Result<(), Error>); - -impl Command for A { +impl<F> Command for F where F: Fn(&mut Context, &Message, Args) -> Result<(), Error> + + Send + + Sync + + ?Sized + + 'static { fn execute(&self, c: &mut Context, m: &Message, a: Args) -> Result<(), Error> { - (self.0)(c, m, a) + (*self)(c, m, a) } } diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs index 7d7cc36..4aadffc 100644 --- a/src/framework/standard/create_group.rs +++ b/src/framework/standard/create_group.rs @@ -1,6 +1,5 @@ pub use super::command::{Command, CommandGroup, CommandOptions, Error as CommandError}; pub(crate) use super::command::CommandOrAlias; -pub(crate) use super::command::A; pub use super::create_command::{CreateCommand, FnOrCommand}; pub use super::Args; @@ -68,21 +67,17 @@ impl CreateGroup { self } - /// Adds a command to group with simplified API. + /// Adds a command to group with a simplified API. /// You can return Err(From::from(string)) if there's an error. pub fn on(self, name: &str, f: fn(&mut Context, &Message, Args) -> Result<(), CommandError>) -> Self { - self._cmd(name, A(f)) + self.cmd(name, f) } /// Like [`on`], but accepts a `Command` directly. /// /// [`on`]: #method.on - pub fn cmd<C: Command + 'static>(self, name: &str, c: C) -> Self { - self._cmd(name, c) - } - - fn _cmd<C: Command + 'static>(mut self, name: &str, c: C) -> Self { + pub fn cmd<C: Command + 'static>(mut self, name: &str, c: C) -> Self { let cmd = Arc::new(c); self.0 @@ -90,7 +85,7 @@ impl CreateGroup { .insert(name.to_string(), CommandOrAlias::Command(cmd)); self - } + } /// If prefix is set, it will be required before all command names. /// For example, if bot prefix is "~" and group prefix is "image" diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index b350a91..ef78f61 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -10,7 +10,7 @@ mod args; pub use self::args::{Args, Iter, FromStrZc, Error as ArgError}; pub(crate) use self::buckets::{Bucket, Ratelimit}; -pub(crate) use self::command::{A, Help}; +pub(crate) use self::command::Help; pub use self::command::{Command, CommandGroup, CommandOptions, Error as CommandError}; pub use self::command::CommandOrAlias; pub use self::configuration::Configuration; @@ -634,18 +634,14 @@ impl StandardFramework { pub fn on(self, name: &str, f: fn(&mut Context, &Message, Args) -> Result<(), CommandError>) -> Self { - self._cmd(name, A(f)) + self.cmd(name, f) } /// Same as [`on`], but accepts a [`Command`] directly. /// /// [`on`]: #method.on /// [`Command`]: trait.Command.html - pub fn cmd<C: Command + 'static>(self, name: &str, c: C) -> Self { - self._cmd(name, c) - } - - fn _cmd<C: Command + 'static>(mut self, name: &str, c: C) -> Self { + pub fn cmd<C: Command + 'static>(mut self, name: &str, c: C) -> Self { { let ungrouped = self.groups .entry("Ungrouped".to_string()) |