Change execution_allowed to a match for shorter reading.

This commit is contained in:
projectmoon 2021-05-26 21:12:21 +00:00
parent 8f5b6f0636
commit 1ebd13e912
1 changed files with 4 additions and 8 deletions

View File

@ -109,14 +109,10 @@ pub trait Command: Send + Sync {
/// ever. Later, we can add stuff like admin/regular user power
/// separation, etc.
fn execution_allowed(cmd: &(impl Command + ?Sized), ctx: &Context<'_>) -> Result<(), CommandError> {
if cmd.is_secure() {
if ctx.is_secure() {
Ok(())
} else {
Err(CommandError::InsecureExecution)
}
} else {
Ok(())
match cmd {
cmd if cmd.is_secure() && ctx.is_secure() => Ok(()),
cmd if cmd.is_secure() && !ctx.is_secure() => Err(CommandError::InsecureExecution),
_ => Ok(()),
}
}