fix: config to file and import optimize
does not need to be module
This commit is contained in:
parent
4e0bb7dfa3
commit
11317787f6
1 changed files with 0 additions and 0 deletions
|
@ -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)),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue