use std::fs; use serde::Deserialize; #[derive(Deserialize, Copy, Clone)] pub struct Config { pub latitude: f64, pub longitude: f64, } #[derive(Deserialize)] #[serde(rename_all = "kebab-case")] struct CompleteConfig { seasonal_clock: Config, } pub fn get_config() -> Option { let xdg_dirs = xdg::BaseDirectories::new().unwrap(); let config_path = xdg_dirs .place_config_file("seasonal-clock.toml") .expect("cannot create configuration directory"); let data: std::io::Result = fs::read_to_string(config_path); if let Ok(..) = data { let complete_config: CompleteConfig = toml::from_str(&data.unwrap()).unwrap(); Some(complete_config.seasonal_clock) } else { None } }