burncloud_common/
config.rs1use crate::types::Config;
2use anyhow::Result;
3use std::fs;
4use std::path::Path;
5
6pub fn load_config(path: &str) -> Result<Config> {
7 if Path::new(path).exists() {
8 let content = fs::read_to_string(path)?;
9 let config: Config = serde_json::from_str(&content)?;
10 Ok(config)
11 } else {
12 let config = Config::default();
13 save_config(path, &config)?;
14 Ok(config)
15 }
16}
17
18pub fn save_config(path: &str, config: &Config) -> Result<()> {
19 let content = serde_json::to_string_pretty(config)?;
20 fs::write(path, content)?;
21 Ok(())
22}