Add 'data_dir' config option

This commit is contained in:
Joscha 2022-08-25 22:33:25 +02:00
parent 84ff1f068b
commit e40948567a
3 changed files with 31 additions and 8 deletions

View file

@ -1,5 +1,5 @@
use std::fs;
use std::path::Path;
use std::path::{Path, PathBuf};
use serde::Deserialize;
@ -7,6 +7,7 @@ use crate::macros::ok_or_return;
#[derive(Debug, Default, Deserialize)]
pub struct Config {
pub data_dir: Option<PathBuf>,
#[serde(default)]
pub ephemeral: bool,
}
@ -14,6 +15,12 @@ pub struct Config {
impl Config {
pub fn load(path: &Path) -> Self {
let content = ok_or_return!(fs::read_to_string(path), Self::default());
ok_or_return!(toml::from_str(&content), Self::default())
match toml::from_str(&content) {
Ok(config) => config,
Err(err) => {
println!("Error loading config file: {err}");
Self::default()
}
}
}
}