use config::{Config, FileFormat}; use std::fs::File; use std::io::Write; use crate::ui_code::AppState; pub fn load_config() -> AppState { let settings = Config::builder() .add_source(config::File::new("./settings.toml", FileFormat::Toml)) .build(); if let Ok(val) = settings { if let Ok(state) = val.try_deserialize() { state } else { AppState::default() } } else { AppState::default() } } pub fn save_config(config: &AppState) { println!("{}", { if let Ok(toml_str) = toml::to_string(&config) { if let Ok(mut file) = File::create("./settings.toml") { file.write_all(toml_str.as_bytes()).unwrap(); "" } else { "File could not be opened" } } else { "Settings could not be deserialized" } }); }