From f42408c8228dd34cae16ef43315c7168c8578126 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Thu, 11 Jan 2018 18:52:08 +0100 Subject: Define `A` only once --- src/framework/standard/create_command.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/framework') 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 { - let CreateCommand(options, fc) = self; + struct A(Arc, C); - match fc { - FnOrCommand::Fn(func) => { - struct A(Arc, fn(&mut Context, &Message, Args) -> Result<(), CommandError>); + impl Command for A { + 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 { Arc::clone(&self.0) } + } - fn options(&self) -> Arc { 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, Arc); - - 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 { Arc::clone(&self.0) } - } - Arc::new(A(Arc::new(options), cmd)) }, FnOrCommand::CommandWithOptions(cmd) => cmd, -- cgit v1.2.3