From c1d3862ca9272404261236b867daa1f0e8e7dba7 Mon Sep 17 00:00:00 2001 From: Lawal Abubakar Babatunde Date: Fri, 8 Sep 2023 18:03:49 +0100 Subject: [PATCH] chore: refactored code for brevity --- src/utils.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index e341ac2..cc5e439 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -18,24 +18,21 @@ pub fn convert( base_convert_from: &str, ) -> Result<(), std::num::ParseIntError> { let convert_from = get_base_value(base_convert_from); - let convert_to = get_base_value(base_convert_to); + let number = Based::new(number_str, convert_from).to(convert_to).unwrap(); + match base_convert_to { "binary" => { - let number = Based::new(number_str, convert_from).to(convert_to).unwrap(); println!("Binary: {}", number.val); } "hex" => { - let number = Based::new(number_str, convert_from).to(convert_to).unwrap(); println!("Hexadecimal: 0x{}", number.val); } "octal" => { - let number = Based::new(number_str, convert_from).to(convert_to).unwrap(); println!("Octal: {}", number.val); } "decimal" => { - let number = Based::new(number_str, convert_from).to(convert_to).unwrap(); println!("Decimal: {}", number.val); } _ => {