Avoid double evaluation of expression in handle_command! (#349)

This commit is contained in:
Canop 2019-12-16 17:33:50 +01:00 committed by Timon
parent b3cf303295
commit aad7aaced8

View File

@ -32,14 +32,14 @@ macro_rules! handle_command {
#[cfg(windows)] #[cfg(windows)]
{ {
let command = $command;
// ansi code is not always a string, however it does implement `Display` and `Write`. // ansi code is not always a string, however it does implement `Display` and `Write`.
// In order to check if the code is supported we have to make it a string. // In order to check if the code is supported we have to make it a string.
let ansi_code = format!("{}", $command.ansi_code()); let ansi_code = format!("{}", command.ansi_code());
if command.is_ansi_code_supported() {
if $command.is_ansi_code_supported() {
write_ansi_code!($writer, &ansi_code) write_ansi_code!($writer, &ansi_code)
} else { } else {
$command.execute_winapi().map_err($crate::ErrorKind::from) command.execute_winapi().map_err($crate::ErrorKind::from)
} }
} }
#[cfg(unix)] #[cfg(unix)]