fix: config to file and import optimize

does not need to be module
This commit is contained in:
Strix 2023-10-14 22:39:47 +02:00
parent 4e0bb7dfa3
commit 11317787f6
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774

View file

@ -1,30 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub build_by_default: bool,
#[serde(default)]
pub tmp_dir: Option<String>,
}
impl Default for Config {
fn default() -> Config {
Config {
build_by_default: false,
tmp_dir: Some(String::from("/tmp/pkgr"))
}
}
}
impl Config {
pub fn from_path(path: &str) -> Result<Config, String> {
match std::fs::read_to_string(path) {
Ok(s) => match toml::from_str(&s) {
Ok(c) => Ok(c),
Err(e) => Err(format!("failed to parse config: {}", e)),
},
Err(e) => Err(format!("failed to read config: {}", e)),
}
}
}