/
arch_linux
/
rcm
Обзор
Документация
Войти
/
arch_linux
/
rcm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/config.rs
98 строк
3 KB
БАЛИЦКИЙ АЛЕКСАНДР НИКОЛАЕВИЧ
upload files
26 ноя 2025, 10:22
26 ноя 2025, 10:22
35fe12c
Код
Авторство
О чём код?
use serde::{Deserialize, Serialize}; use std::fs; use std::path::PathBuf; #[derive(Debug, Serialize, Deserialize)] pub struct AppConfig { pub default_mode: Mode, pub cli_settings: CliConfig, pub gui_settings: GuiConfig, } #[derive(Debug, Serialize, Deserialize)] pub enum Mode { Cli, Gui, } #[derive(Debug, Serialize, Deserialize)] pub struct CliConfig { pub default_interactive: bool, pub verbose: bool, } #[derive(Debug, Serialize, Deserialize)] pub struct GuiConfig { pub window_width: f32, pub window_height: f32, pub theme: String, } impl Default for AppConfig { fn default() -> Self { Self { default_mode: Mode::Cli, cli_settings: CliConfig { default_interactive: true, verbose: false, }, gui_settings: GuiConfig { window_width: 1000.0, window_height: 700.0, theme: "dark".to_string(), }, } } } impl AppConfig { pub fn load() -> Self { let config_path = Self::get_config_path(); if let Ok(content) = fs::read_to_string(&config_path) { toml::from_str(&content).unwrap_or_else(|e| { eprintln!("⚠️ Ошибка чтения конфига: {}, использую настройки по умолчанию", e); Self::default() }) } else { println!("📁 Конфиг не найден, создаю настройки по умолчанию"); let config = Self::default(); if let Err(e) = config.save() { eprintln!("❌ Ошибка сохранения конфига: {}", e); } config } } pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> { let config_path = Self::get_config_path(); if let Some(parent) = config_path.parent() { fs::create_dir_all(parent)?; } let content = toml::to_string_pretty(self)?; fs::write(&config_path, content)?; println!("💾 Настройки сохранены: {:?}", config_path); Ok(()) } fn get_config_path() -> PathBuf { dirs::config_dir() .unwrap() .join("cargo-ui-manager") .join("config.toml") } } // УДАЛИТЕ весь этот блок - он вызывает ошибку: // impl GuiConfig { // pub fn validate(&self) -> Result<(), String> { // if self.window_width < 400.0 || self.window_width > 4000.0 { // return Err("Ширина окна должна быть между 400 и 4000".to_string()); // } // if self.window_height < 300.0 || self.window_height > 3000.0 { // return Err("Высота окна должна быть между 300 и 3000".to_string()); // } // Ok(()) // } // }