diff options
| author | acdenisSK <[email protected]> | 2018-06-08 15:21:27 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2018-06-08 15:22:52 +0200 |
| commit | caeab28059d029a92b784f3b5ae1f79c412c8404 (patch) | |
| tree | 8cd41b07fbd710befe11f05a026b184b159700c4 /src/framework/standard/command.rs | |
| parent | Bump to v0.5.4 (diff) | |
| download | serenity-caeab28059d029a92b784f3b5ae1f79c412c8404.tar.xz serenity-caeab28059d029a92b784f3b5ae1f79c412c8404.zip | |
Handle debug impls better
Diffstat (limited to 'src/framework/standard/command.rs')
| -rw-r--r-- | src/framework/standard/command.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs index 8c35451..d8fc81e 100644 --- a/src/framework/standard/command.rs +++ b/src/framework/standard/command.rs @@ -12,11 +12,29 @@ use std::{ use utils::Colour; use super::{Args, Configuration, HelpBehaviour}; -pub type Check = Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool +type CheckFunction = Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool + Send + Sync + 'static; +pub struct Check(pub(crate) Box<CheckFunction>); + +impl Check { + pub(crate) fn new<F: Send + Sync + 'static>(f: F) -> Self + where F: Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool + { + Check(Box::new(f)) + } +} + +impl Debug for Check { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.debug_tuple("Check") + .field(&"<fn>") + .finish() + } +} + pub type HelpFunction = fn(&mut Context, &Message, &HelpOptions, HashMap<String, Arc<CommandGroup>>, &Args) -> Result<(), Error>; @@ -24,7 +42,9 @@ pub struct Help(pub HelpFunction, pub Arc<HelpOptions>); impl Debug for Help { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "fn()") + f.debug_struct("Help") + .field("options", &self.1) + .finish() } } @@ -49,7 +69,7 @@ impl fmt::Debug for CommandOrAlias { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CommandOrAlias::Alias(ref s) => f.debug_tuple("CommandOrAlias::Alias").field(&s).finish(), - _ => Ok(()) + CommandOrAlias::Command(ref arc) => f.debug_tuple("CommandOrAlias::Command").field(&arc.options()).finish(), } } } @@ -97,10 +117,11 @@ impl Default for CommandGroup { } } +#[derive(Debug)] pub struct CommandOptions { /// A set of checks to be called prior to executing the command. The checks /// will short-circuit on the first check that returns `false`. - pub checks: Vec<Box<Check>>, + pub checks: Vec<Check>, /// Ratelimit bucket. pub bucket: Option<String>, /// Command description, used by other commands. @@ -287,25 +308,6 @@ impl<F> Command for F where F: Fn(&mut Context, &Message, Args) -> Result<(), Er } } -impl fmt::Debug for CommandOptions { - // TODO: add CommandOptions::checks somehow? - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("CommandOptions") - .field("bucket", &self.bucket) - .field("desc", &self.desc) - .field("example", &self.example) - .field("usage", &self.usage) - .field("min_args", &self.min_args) - .field("required_permissions", &self.required_permissions) - .field("allowed_roles", &self.allowed_roles) - .field("help_available", &self.help_available) - .field("dm_only", &self.dm_only) - .field("guild_only", &self.guild_only) - .field("owners_only", &self.owners_only) - .finish() - } -} - impl Default for CommandOptions { fn default() -> CommandOptions { CommandOptions { |