From d075958732b9deb6a6f39dd1171144e075f013dc Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Wed, 26 Mar 2025 21:23:12 +0300 Subject: Fixing errors, the zsh: command not found: main branch will pushed only after fixing all mistakes and bugs. Now founded 3.] --- src/configmanager.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/configmanager.rs') diff --git a/src/configmanager.rs b/src/configmanager.rs index c0047a5..c005d2c 100644 --- a/src/configmanager.rs +++ b/src/configmanager.rs @@ -1,22 +1,25 @@ use std::fs; use serde::Deserialize; use dirs::home_dir; -use std::path::PathBuf; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Config { - pub lat: String, - pub lon: String, + pub lat: f64, + pub lon: f64, pub exclude: String, - pub appid: String, - pub lang: String, - pub units: String, - pub cache: bool, - pub rain: String, - pub sunny: String, - pub snowy: String, + pub appid: String, + pub lang: String, + pub units: String, + pub cache: bool, + pub rain: String, + pub sunny: String, + pub snowy: String, } +type BoxedError = Box; + + + pub fn handle_config(_config: &Config) -> Result<(), Box> { Ok(()) } @@ -24,15 +27,20 @@ pub fn handle_config(_config: &Config) -> Result<(), Box> pub fn gen_standard_conf() { // TODO: Implement } - + impl Config { pub fn load() -> Result> { let mut path = home_dir().ok_or("Home directory not found")?; path.push(".config/WeatherFetch/Config.toml"); - let config_str = fs::read_to_string(path)?; - let config: Config = toml::from_str(&config_str)?; + let config_str = fs::read_to_string(&path) + .map_err(|e| format!("Failed to read config: {}", e))?; + + let config: Config = toml::from_str(&config_str) + .map_err(|e| format!("Invalid TOML: {}", e))?; + Ok(config) } } + -- cgit v1.2.3