use serde::{Deserialize, Serialize}; use std::fs; #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub host: String, pub port: u16, pub debug: bool, } impl Config { // Чтение из YAML pub fn load(path: &str) -> Result> { let contents = fs::read_to_string(path)?; let config: Config = serde_yaml::from_str(&contents)?; Ok(config) } // Запись в YAML pub fn save(&self, path: &str) -> Result<(), Box> { let yaml_string = serde_yaml::to_string(self)?; fs::write(path, yaml_string)?; Ok(()) } }