use std::fs; use anyhow::anyhow; use serde::Deserialize; #[derive(Deserialize)] pub struct Logo { pub path: String, pub width: String, pub height: String, pub alt: String, } #[derive(Deserialize)] pub struct Config { pub name: String, pub description: String, pub path: String, pub logo: Option<Logo>, } impl Config { pub fn load() -> anyhow::Result<Self> { let file_contents = read_conf_file()?; let config = toml::from_str(&file_contents)?; Ok(config) } } fn read_conf_file() -> anyhow::Result<String> { let filenames = ["config.toml", "/etc/org_flux/config.toml"]; for filename in filenames.iter() { if let Ok(x) = fs::read_to_string(filename) { return Ok(x); } } Err(anyhow!("Could not open config file")) }