refactor: rewrite fn signature and remove match
This commit is contained in:
parent
2c331c4ed7
commit
cad9823c83
|
@ -6,7 +6,7 @@ use crate::{
|
|||
};
|
||||
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 parsed_input: String = input
|
||||
.buffer()
|
||||
|
@ -16,16 +16,12 @@ pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool)
|
|||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let operation = if mode {
|
||||
let operation = if !state {
|
||||
HammingMode::Encrypt
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue