From aad7aaced82a2d62cbe5e204c0827ac1dfac2636 Mon Sep 17 00:00:00 2001 From: Canop Date: Mon, 16 Dec 2019 17:33:50 +0100 Subject: [PATCH] Avoid double evaluation of expression in handle_command! (#349) --- src/macros.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 9377865..c2a1539 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -32,14 +32,14 @@ macro_rules! handle_command { #[cfg(windows)] { + let command = $command; // 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. - let ansi_code = format!("{}", $command.ansi_code()); - - if $command.is_ansi_code_supported() { + let ansi_code = format!("{}", command.ansi_code()); + if command.is_ansi_code_supported() { write_ansi_code!($writer, &ansi_code) } else { - $command.execute_winapi().map_err($crate::ErrorKind::from) + command.execute_winapi().map_err($crate::ErrorKind::from) } } #[cfg(unix)]