From 3f57120e539c14a04fa7158999fdc60db7ad46e7 Mon Sep 17 00:00:00 2001 From: primardj Date: Mon, 15 Apr 2024 23:24:24 +0100 Subject: [PATCH] change a big if chain by a match. --- .../sv-rustit/src/executor/sent_signal.rs | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs index 5f721b5..1e1e1f6 100644 --- a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs +++ b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs @@ -6,53 +6,53 @@ use crate::status_obj; pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_obj::StatusObj) -> i32 { // Return 0 in case everything worked fine, return 1 if timeout or error. - if command == "s" { - // case command is status - return misc::print_status(sv); - } - - if command == "u" { - // case where command is up - if sv.sent_signal(b"u") { - if verbose == 1 { - return misc::run_verbose(true, svwait_var, sv); - } else { - return 0; + match command { + "s" => { + // case command is status + return misc::print_status(sv); + }, + "u" => { + // case where command is up + if sv.sent_signal(b"u") { + if verbose == 1 { + return misc::run_verbose(true, svwait_var, sv); + } else { + return 0; + } + } else { + return 1; } - } else { + }, + "d" => { + // case where command is up + if sv.sent_signal(b"d") { + if verbose == 1 { + return misc::run_verbose(false, svwait_var, sv); + } else { + return 0; + } + } else { + return 1; + } + }, + "o" => { + // case where command is run once. + if sv.sent_signal(b"o") { + if verbose == 1 { + return misc::run_verbose(true, svwait_var, sv); + } else { + return 0; + } + } else { + return 1; + } + }, + other => { + println!("Error, command {} not implemented.", other); // TODO : Put the real error + // message. return 1; } - } - - if command == "d" { - // case where command is up - if sv.sent_signal(b"d") { - if verbose == 1 { - return misc::run_verbose(false, svwait_var, sv); - } else { - return 0; - } - } else { - return 1; - } - } - - if command == "o" { - // case where command is run once. - if sv.sent_signal(b"o") { - if verbose == 1 { - return misc::run_verbose(true, svwait_var, sv); - } else { - return 0; - } - } else { - return 1; - } - } - - - println!("Error, command not implemented."); - return 1; + }; }