use std::collections::HashMap; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::Path; #[derive(Debug, Clone)] pub struct Config { values: HashMap, } impl Config { pub fn from_file>(path: P) -> Result> { let file = File::open(path)?; let reader = BufReader::new(file); let mut values = HashMap::new(); for line in reader.lines() { let line = line?; if line.trim().is_empty() || line.trim_start().starts_with('#') { continue; } if let Some((key, value)) = line.split_once('=') { values.insert(key.trim().to_string(), value.trim().to_string()); } } Ok(Self { values }) } pub fn get(&self, key: &str) -> Result { self.values .get(key) .cloned() .ok_or_else(|| format!("Konfigurationsschlüssel nicht gefunden: {key}")) } }