From 0ac84bd50407f2c4747a64b5340003849439fa52 Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Tue, 25 Mar 2025 20:09:50 +0300 Subject: Fixed errors and bugs. --- src/configmanager.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/configmanager.rs') diff --git a/src/configmanager.rs b/src/configmanager.rs index c124419..fb8ccc1 100644 --- a/src/configmanager.rs +++ b/src/configmanager.rs @@ -1,5 +1,7 @@ use std::fs; use serde::Deserialize; +use dirs::home_dir; +use std::path::PathBuf; impl WeatherFetch{ #[derive(Deserialize)] @@ -10,19 +12,32 @@ pub struct Config { appid: String, //Your OpenWeatherMap API key lang: String, //Output language units: String, //Units of measurement - cache: bool //Cacheing next Weather to dont use internet in next call + cache: bool, //Cacheing next Weather to dont use internet in next call rain: String, //Path to rain image (png/jpg) or ASCII art int .txt sunny: String, //Path to sunny image (png/jpg) or ASCII art int .txt snowy: String, } //More info: OpenWeatherMap.org/api/one-call3 -pub fn handle_config() -> Result<(), Box>{ - let Config_str = fs::read_to_string("~/.config/WeatherFetch/Config.toml"); - let Config_parse: Config = toml::from_str(&data)?.except(); +impl Config{ + pub fn load() -> Result> { + let mut path = home_dir().ok_or("Не удалось найти домашнюю директорию")?; + path.push(".config/WeatherFetch/Config.toml"); + + let config_str = fs::read_to_string(path)?; + let config: Config = toml::from_str(&config_str)?; + Ok(config) + } } + +pub fn handle_config(config: &Config) -> Result<(), Box> { + // Пока недоделано + Ok(()) } pub fn gen_standart_conf() { } + +} + -- cgit v1.2.3