refactor: rewrite fn signature and remove match

This commit is contained in:
doryan 2024-08-10 01:09:35 +04:00
parent 2c331c4ed7
commit cad9823c83

View File

@ -6,7 +6,7 @@ use crate::{
}; };
use gtk::{prelude::*, *}; use gtk::{prelude::*, *};
pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool) { pub fn start_hamming_algorithm(input: &TextView, state: bool) -> Result<String> {
let (iter_start, iter_end) = input.buffer().bounds(); let (iter_start, iter_end) = input.buffer().bounds();
let parsed_input: String = input let parsed_input: String = input
.buffer() .buffer()
@ -16,16 +16,12 @@ pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool)
.parse() .parse()
.unwrap(); .unwrap();
let operation = if mode { let operation = if !state {
HammingMode::Encrypt HammingMode::Encrypt
} else { } else {
HammingMode::Decrypt HammingMode::Decrypt
}; };
match hamming(parsed_input, operation) {
Ok(res) => output.buffer().set_text(res.trim_end()),
Err(rej) => output.buffer().set_text(rej.as_str()),
}
hamming(parsed_input, operation) hamming(parsed_input, operation)
} }