fix(fn): use &str in the function arguments instead of &String and refactor function code with use &str

This commit is contained in:
doryan 2024-08-10 00:50:52 +04:00
parent cd6403fb32
commit e9dbcb272e

View File

@ -23,19 +23,13 @@ pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool)
Ok(res) => output.buffer().set_text(res.trim_end()), Ok(res) => output.buffer().set_text(res.trim_end()),
Err(rej) => output.buffer().set_text(rej.as_str()), Err(rej) => output.buffer().set_text(rej.as_str()),
} }
hamming(parsed_input, operation)
} }
pub fn check_correct_binary_code( pub fn check_correct_binary_code(input: &str, prepared_input: &str, l: usize) -> (bool, bool) {
input: &String, let first_condition: bool = prepared_input.len() % l == 0;
prepared_input: &String,
l: usize,
) -> (bool, bool) {
let first_condition: bool = input
.as_str()
.chars()
.all(|c| c == '1' || c == '0' || c == ' ');
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) (first_condition, second_condition)
} }