refactor: change import and function signature

SignalReduce model import has been added instead Infobar.
Return value in function signature has been changed (Option<[f64; 6]> ->
Result<SignalReduce, ParseFloarError>).
This commit is contained in:
doryan 2024-08-03 00:06:22 +04:00
parent 81b22a14c9
commit cbde9a8af1

View File

@ -7,7 +7,7 @@ use gtk::{
TextBuffer, TextBuffer,
}; };
use crate::view::components::{info_bar::InfoBar, input::Input}; use crate::{model::models::SignalReduce, view::components::input::Input};
pub fn get_error_message(error_instance: ParseFloatError) -> Option<&'static str> { pub fn get_error_message(error_instance: ParseFloatError) -> Option<&'static str> {
match error_instance.to_string().as_str() { match error_instance.to_string().as_str() {
@ -17,11 +17,9 @@ pub fn get_error_message(error_instance: ParseFloatError) -> Option<&'static str
} }
} }
pub fn parse_fields(all_inputs: Vec<Input>) -> Option<[f64; 6]> { pub fn parse_fields(all_inputs: Vec<Input>) -> Result<SignalReduce, ParseFloatError> {
let mut values: [f64; 6] = [0f64; 6]; let mut values: [f64; 6] = [0f64; 6];
let info_bar = InfoBar::get_instance();
for (i, input) in all_inputs.iter().enumerate() { for (i, input) in all_inputs.iter().enumerate() {
let input_text_buffer: TextBuffer = input.clone().get_input().buffer(); let input_text_buffer: TextBuffer = input.clone().get_input().buffer();
let try_extract_value = f64::from_str( let try_extract_value = f64::from_str(
@ -36,16 +34,11 @@ pub fn parse_fields(all_inputs: Vec<Input>) -> Option<[f64; 6]> {
); );
match try_extract_value { match try_extract_value {
Ok(value) => values[i] = value, Ok(value) => values[i] = value,
Err(error) => { Err(error) => return Err(error),
let error_kind: Option<&str> = get_error_message(error);
info_bar.set_text_label(error_kind);
info_bar.show_infobar(5u64);
return None;
}
} }
} }
Some(values) Ok(SignalReduce(
values[0], values[1], values[2], values[3], values[4], values[5],
))
} }