Remove Box<dyn Command> conversion impls for map in macro.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
projectmoon 2021-05-30 22:49:28 +00:00
parent b7393c1907
commit 494d28486e
8 changed files with 7 additions and 100 deletions

View File

@ -10,12 +10,6 @@ use std::convert::TryFrom;
pub struct RollCommand(pub ElementExpression); pub struct RollCommand(pub ElementExpression);
impl From<RollCommand> for Box<dyn Command> {
fn from(cmd: RollCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for RollCommand { impl TryFrom<String> for RollCommand {
type Error = BotError; type Error = BotError;

View File

@ -15,12 +15,6 @@ impl PoolRollCommand {
} }
} }
impl From<PoolRollCommand> for Box<dyn Command> {
fn from(cmd: PoolRollCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for PoolRollCommand { impl TryFrom<String> for PoolRollCommand {
type Error = BotError; type Error = BotError;

View File

@ -11,12 +11,6 @@ use std::convert::TryFrom;
pub struct CthRoll(pub DiceRoll); pub struct CthRoll(pub DiceRoll);
impl From<CthRoll> for Box<dyn Command> {
fn from(cmd: CthRoll) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for CthRoll { impl TryFrom<String> for CthRoll {
type Error = BotError; type Error = BotError;
@ -51,12 +45,6 @@ impl Command for CthRoll {
pub struct CthAdvanceRoll(pub AdvancementRoll); pub struct CthAdvanceRoll(pub AdvancementRoll);
impl From<CthAdvanceRoll> for Box<dyn Command> {
fn from(cmd: CthAdvanceRoll) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for CthAdvanceRoll { impl TryFrom<String> for CthAdvanceRoll {
type Error = BotError; type Error = BotError;

View File

@ -9,12 +9,6 @@ use std::convert::{Into, TryFrom};
pub struct RegisterCommand; pub struct RegisterCommand;
impl From<RegisterCommand> for Box<dyn Command> {
fn from(cmd: RegisterCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for RegisterCommand { impl TryFrom<String> for RegisterCommand {
type Error = BotError; type Error = BotError;
@ -56,12 +50,6 @@ impl Command for RegisterCommand {
pub struct UnlinkCommand(pub String); pub struct UnlinkCommand(pub String);
impl From<UnlinkCommand> for Box<dyn Command> {
fn from(cmd: UnlinkCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for UnlinkCommand { impl TryFrom<String> for UnlinkCommand {
type Error = BotError; type Error = BotError;
@ -99,12 +87,6 @@ impl Command for UnlinkCommand {
pub struct LinkCommand(pub String); pub struct LinkCommand(pub String);
impl From<LinkCommand> for Box<dyn Command> {
fn from(cmd: LinkCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for LinkCommand { impl TryFrom<String> for LinkCommand {
type Error = BotError; type Error = BotError;
@ -144,12 +126,6 @@ impl Command for LinkCommand {
pub struct CheckCommand; pub struct CheckCommand;
impl From<CheckCommand> for Box<dyn Command> {
fn from(cmd: CheckCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for CheckCommand { impl TryFrom<String> for CheckCommand {
type Error = BotError; type Error = BotError;
@ -174,14 +150,17 @@ impl Command for CheckCommand {
match user { match user {
Some(user) => match user.password { Some(user) => match user.password {
Some(_) => Execution::success( 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( None => Execution::success(
"Account exists, but is not available to external applications.".to_string(), "Account exists, but is not available to external applications.".to_string(),
), ),
}, },
None => Execution::success( 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; pub struct UnregisterCommand;
impl From<UnregisterCommand> for Box<dyn Command> {
fn from(cmd: UnregisterCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for UnregisterCommand { impl TryFrom<String> for UnregisterCommand {
type Error = BotError; type Error = BotError;

View File

@ -7,12 +7,6 @@ use std::convert::TryFrom;
pub struct HelpCommand(pub Option<HelpTopic>); pub struct HelpCommand(pub Option<HelpTopic>);
impl From<HelpCommand> for Box<dyn Command> {
fn from(cmd: HelpCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for HelpCommand { impl TryFrom<String> for HelpCommand {
type Error = BotError; type Error = BotError;

View File

@ -65,7 +65,7 @@ fn split_command(input: &str) -> Result<(String, String), CommandParsingError> {
/// boilerplate. /// boilerplate.
macro_rules! convert_to { macro_rules! convert_to {
($type:ident, $input: expr) => { ($type:ident, $input: expr) => {
$type::try_from($input).map(Into::into) $type::try_from($input).map(|cmd| Box::new(cmd) as Box<dyn Command>)
}; };
} }
@ -81,7 +81,7 @@ pub fn parse_command(input: &str) -> Result<Box<dyn Command>, BotError> {
"del" => convert_to!(DeleteVariableCommand, cmd_input), "del" => convert_to!(DeleteVariableCommand, cmd_input),
"r" | "roll" => convert_to!(RollCommand, cmd_input), "r" | "roll" => convert_to!(RollCommand, cmd_input),
"rp" | "pool" => convert_to!(PoolRollCommand, 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<dyn Command>),
"cthroll" => convert_to!(CthRoll, cmd_input), "cthroll" => convert_to!(CthRoll, cmd_input),
"cthadv" | "ctharoll" => convert_to!(CthAdvanceRoll, cmd_input), "cthadv" | "ctharoll" => convert_to!(CthAdvanceRoll, cmd_input),
"help" => convert_to!(HelpCommand, cmd_input), "help" => convert_to!(HelpCommand, cmd_input),

View File

@ -85,12 +85,6 @@ async fn get_rooms_for_user(
pub struct ListRoomsCommand; pub struct ListRoomsCommand;
impl From<ListRoomsCommand> for Box<dyn Command> {
fn from(cmd: ListRoomsCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for ListRoomsCommand { impl TryFrom<String> for ListRoomsCommand {
type Error = BotError; type Error = BotError;
@ -126,12 +120,6 @@ impl Command for ListRoomsCommand {
pub struct SetRoomCommand(String); pub struct SetRoomCommand(String);
impl From<SetRoomCommand> for Box<dyn Command> {
fn from(cmd: SetRoomCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for SetRoomCommand { impl TryFrom<String> for SetRoomCommand {
type Error = BotError; type Error = BotError;

View File

@ -8,12 +8,6 @@ use std::convert::TryFrom;
pub struct GetAllVariablesCommand; pub struct GetAllVariablesCommand;
impl From<GetAllVariablesCommand> for Box<dyn Command> {
fn from(cmd: GetAllVariablesCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for GetAllVariablesCommand { impl TryFrom<String> for GetAllVariablesCommand {
type Error = BotError; type Error = BotError;
@ -57,12 +51,6 @@ impl Command for GetAllVariablesCommand {
pub struct GetVariableCommand(pub String); pub struct GetVariableCommand(pub String);
impl From<GetVariableCommand> for Box<dyn Command> {
fn from(cmd: GetVariableCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for GetVariableCommand { impl TryFrom<String> for GetVariableCommand {
type Error = BotError; type Error = BotError;
@ -101,12 +89,6 @@ impl Command for GetVariableCommand {
pub struct SetVariableCommand(pub String, pub i32); pub struct SetVariableCommand(pub String, pub i32);
impl From<SetVariableCommand> for Box<dyn Command> {
fn from(cmd: SetVariableCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for SetVariableCommand { impl TryFrom<String> for SetVariableCommand {
type Error = BotError; type Error = BotError;
@ -142,12 +124,6 @@ impl Command for SetVariableCommand {
pub struct DeleteVariableCommand(pub String); pub struct DeleteVariableCommand(pub String);
impl From<DeleteVariableCommand> for Box<dyn Command> {
fn from(cmd: DeleteVariableCommand) -> Self {
Box::new(cmd)
}
}
impl TryFrom<String> for DeleteVariableCommand { impl TryFrom<String> for DeleteVariableCommand {
type Error = BotError; type Error = BotError;