From 494d28486eb0602b72f13e15cc2f625c82df7456 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Sun, 30 May 2021 22:49:28 +0000 Subject: [PATCH] Remove Box conversion impls for map in macro. --- src/commands/basic_rolling.rs | 6 ------ src/commands/cofd.rs | 6 ------ src/commands/cthulhu.rs | 12 ------------ src/commands/management.rs | 37 +++++------------------------------ src/commands/misc.rs | 6 ------ src/commands/parser.rs | 4 ++-- src/commands/rooms.rs | 12 ------------ src/commands/variables.rs | 24 ----------------------- 8 files changed, 7 insertions(+), 100 deletions(-) diff --git a/src/commands/basic_rolling.rs b/src/commands/basic_rolling.rs index ea868bb..59c73f9 100644 --- a/src/commands/basic_rolling.rs +++ b/src/commands/basic_rolling.rs @@ -10,12 +10,6 @@ use std::convert::TryFrom; pub struct RollCommand(pub ElementExpression); -impl From for Box { - fn from(cmd: RollCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for RollCommand { type Error = BotError; diff --git a/src/commands/cofd.rs b/src/commands/cofd.rs index 0f8f794..e5bc37f 100644 --- a/src/commands/cofd.rs +++ b/src/commands/cofd.rs @@ -15,12 +15,6 @@ impl PoolRollCommand { } } -impl From for Box { - fn from(cmd: PoolRollCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for PoolRollCommand { type Error = BotError; diff --git a/src/commands/cthulhu.rs b/src/commands/cthulhu.rs index 5600c70..80f18cd 100644 --- a/src/commands/cthulhu.rs +++ b/src/commands/cthulhu.rs @@ -11,12 +11,6 @@ use std::convert::TryFrom; pub struct CthRoll(pub DiceRoll); -impl From for Box { - fn from(cmd: CthRoll) -> Self { - Box::new(cmd) - } -} - impl TryFrom for CthRoll { type Error = BotError; @@ -51,12 +45,6 @@ impl Command for CthRoll { pub struct CthAdvanceRoll(pub AdvancementRoll); -impl From for Box { - fn from(cmd: CthAdvanceRoll) -> Self { - Box::new(cmd) - } -} - impl TryFrom for CthAdvanceRoll { type Error = BotError; diff --git a/src/commands/management.rs b/src/commands/management.rs index 976ce76..a66b28c 100644 --- a/src/commands/management.rs +++ b/src/commands/management.rs @@ -9,12 +9,6 @@ use std::convert::{Into, TryFrom}; pub struct RegisterCommand; -impl From for Box { - fn from(cmd: RegisterCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for RegisterCommand { type Error = BotError; @@ -56,12 +50,6 @@ impl Command for RegisterCommand { pub struct UnlinkCommand(pub String); -impl From for Box { - fn from(cmd: UnlinkCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for UnlinkCommand { type Error = BotError; @@ -99,12 +87,6 @@ impl Command for UnlinkCommand { pub struct LinkCommand(pub String); -impl From for Box { - fn from(cmd: LinkCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for LinkCommand { type Error = BotError; @@ -144,12 +126,6 @@ impl Command for LinkCommand { pub struct CheckCommand; -impl From for Box { - fn from(cmd: CheckCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for CheckCommand { type Error = BotError; @@ -174,14 +150,17 @@ impl Command for CheckCommand { match user { Some(user) => match user.password { Some(_) => Execution::success( - "Account exists, and is available to external applications with a password. If you forgot your password, change it with !link.".to_string(), + "Account exists, and is available to external applications with a password. \ + If you forgot your password, change it with !link." + .to_string(), ), None => Execution::success( "Account exists, but is not available to external applications.".to_string(), ), }, None => Execution::success( - "No account registered. Only simple commands in public rooms are available.".to_string(), + "No account registered. Only simple commands in public rooms are available." + .to_string(), ), } } @@ -189,12 +168,6 @@ impl Command for CheckCommand { pub struct UnregisterCommand; -impl From for Box { - fn from(cmd: UnregisterCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for UnregisterCommand { type Error = BotError; diff --git a/src/commands/misc.rs b/src/commands/misc.rs index 709f5f1..c483d6b 100644 --- a/src/commands/misc.rs +++ b/src/commands/misc.rs @@ -7,12 +7,6 @@ use std::convert::TryFrom; pub struct HelpCommand(pub Option); -impl From for Box { - fn from(cmd: HelpCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for HelpCommand { type Error = BotError; diff --git a/src/commands/parser.rs b/src/commands/parser.rs index c9c7cbe..30ca7a4 100644 --- a/src/commands/parser.rs +++ b/src/commands/parser.rs @@ -65,7 +65,7 @@ fn split_command(input: &str) -> Result<(String, String), CommandParsingError> { /// boilerplate. macro_rules! convert_to { ($type:ident, $input: expr) => { - $type::try_from($input).map(Into::into) + $type::try_from($input).map(|cmd| Box::new(cmd) as Box) }; } @@ -81,7 +81,7 @@ pub fn parse_command(input: &str) -> Result, BotError> { "del" => convert_to!(DeleteVariableCommand, cmd_input), "r" | "roll" => convert_to!(RollCommand, cmd_input), "rp" | "pool" => convert_to!(PoolRollCommand, cmd_input), - "chance" => PoolRollCommand::chance_die().map(Into::into), + "chance" => PoolRollCommand::chance_die().map(|cmd| Box::new(cmd) as Box), "cthroll" => convert_to!(CthRoll, cmd_input), "cthadv" | "ctharoll" => convert_to!(CthAdvanceRoll, cmd_input), "help" => convert_to!(HelpCommand, cmd_input), diff --git a/src/commands/rooms.rs b/src/commands/rooms.rs index 3cb3761..0b9205a 100644 --- a/src/commands/rooms.rs +++ b/src/commands/rooms.rs @@ -85,12 +85,6 @@ async fn get_rooms_for_user( pub struct ListRoomsCommand; -impl From for Box { - fn from(cmd: ListRoomsCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for ListRoomsCommand { type Error = BotError; @@ -126,12 +120,6 @@ impl Command for ListRoomsCommand { pub struct SetRoomCommand(String); -impl From for Box { - fn from(cmd: SetRoomCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for SetRoomCommand { type Error = BotError; diff --git a/src/commands/variables.rs b/src/commands/variables.rs index 26124d5..dceacab 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -8,12 +8,6 @@ use std::convert::TryFrom; pub struct GetAllVariablesCommand; -impl From for Box { - fn from(cmd: GetAllVariablesCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for GetAllVariablesCommand { type Error = BotError; @@ -57,12 +51,6 @@ impl Command for GetAllVariablesCommand { pub struct GetVariableCommand(pub String); -impl From for Box { - fn from(cmd: GetVariableCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for GetVariableCommand { type Error = BotError; @@ -101,12 +89,6 @@ impl Command for GetVariableCommand { pub struct SetVariableCommand(pub String, pub i32); -impl From for Box { - fn from(cmd: SetVariableCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for SetVariableCommand { type Error = BotError; @@ -142,12 +124,6 @@ impl Command for SetVariableCommand { pub struct DeleteVariableCommand(pub String); -impl From for Box { - fn from(cmd: DeleteVariableCommand) -> Self { - Box::new(cmd) - } -} - impl TryFrom for DeleteVariableCommand { type Error = BotError;