diff options
| author | acdenisSK <[email protected]> | 2018-01-11 18:52:08 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2018-01-11 18:52:08 +0100 |
| commit | f42408c8228dd34cae16ef43315c7168c8578126 (patch) | |
| tree | 9380dffad5ea77693da1b6ce452bbec9c9bf0a9c /src/framework | |
| parent | Fix ShardManager doctest (diff) | |
| download | serenity-f42408c8228dd34cae16ef43315c7168c8578126.tar.xz serenity-f42408c8228dd34cae16ef43315c7168c8578126.zip | |
Define `A` only once
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/create_command.rs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/framework/standard/create_command.rs b/src/framework/standard/create_command.rs index 6450b64..c825e67 100644 --- a/src/framework/standard/create_command.rs +++ b/src/framework/standard/create_command.rs @@ -207,33 +207,23 @@ impl CreateCommand { } pub(crate) fn finish(self) -> Arc<Command> { - let CreateCommand(options, fc) = self; + struct A<C: Command>(Arc<CommandOptions>, C); - match fc { - FnOrCommand::Fn(func) => { - struct A(Arc<CommandOptions>, fn(&mut Context, &Message, Args) -> Result<(), CommandError>); + impl<C: Command> Command for A<C> { + fn execute(&self, c: &mut Context, m: &Message, a: Args) -> Result<(), CommandError> { + self.1.execute(c, m, a) + } - impl Command for A { - fn execute(&self, c: &mut Context, m: &Message, a: Args) -> Result<(), CommandError> { - (self.1)(c, m, a) - } + fn options(&self) -> Arc<CommandOptions> { Arc::clone(&self.0) } + } - fn options(&self) -> Arc<CommandOptions> { Arc::clone(&self.0) } - } + let CreateCommand(options, fc) = self; + match fc { + FnOrCommand::Fn(func) => { Arc::new(A(Arc::new(options), func)) }, FnOrCommand::Command(cmd) => { - struct A(Arc<CommandOptions>, Arc<Command>); - - impl Command for A { - fn execute(&self, c: &mut Context, m: &Message, a: Args) -> Result<(), CommandError> { - self.1.execute(c, m, a) - } - - fn options(&self) -> Arc<CommandOptions> { Arc::clone(&self.0) } - } - Arc::new(A(Arc::new(options), cmd)) }, FnOrCommand::CommandWithOptions(cmd) => cmd, |