From e9dbcb272ed9663f6e002232ea9912871b9b647b Mon Sep 17 00:00:00 2001 From: doryan Date: Sat, 10 Aug 2024 00:50:52 +0400 Subject: [PATCH] fix(fn): use &str in the function arguments instead of &String and refactor function code with use &str --- .../view_utils/hamming_code_input_utils.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/controller/view_utils/hamming_code_input_utils.rs b/src/controller/view_utils/hamming_code_input_utils.rs index 03e7f69..2113fd0 100644 --- a/src/controller/view_utils/hamming_code_input_utils.rs +++ b/src/controller/view_utils/hamming_code_input_utils.rs @@ -23,19 +23,13 @@ pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool) Ok(res) => output.buffer().set_text(res.trim_end()), Err(rej) => output.buffer().set_text(rej.as_str()), } + hamming(parsed_input, operation) } -pub fn check_correct_binary_code( - input: &String, - prepared_input: &String, - l: usize, -) -> (bool, bool) { - let first_condition: bool = input - .as_str() - .chars() - .all(|c| c == '1' || c == '0' || c == ' '); +pub fn check_correct_binary_code(input: &str, prepared_input: &str, l: usize) -> (bool, bool) { + let first_condition: bool = prepared_input.len() % l == 0; - let second_condition: bool = prepared_input.len() % l == 0; + let second_condition: bool = input.chars().all(|c| c == '1' || c == '0' || c == ' '); (first_condition, second_condition) }