use std::path::Path;
use crate::settings::AppSettings;
pub fn from_file(path: &Path) -> Result<AppSettings, Box<dyn std::error::Error>> {
let text = std::fs::read_to_string(path)?;
Ok(toml::from_str(&text)?)
}
pub fn from_file_or_default(path: &Path) -> AppSettings {
from_file(path).unwrap_or_default()
}
pub fn to_file(settings: &AppSettings, path: &Path) -> Result<(), Box<dyn std::error::Error>> {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
std::fs::write(path, toml::to_string_pretty(settings)?)?;
Ok(())
}