don't panic on missing/invalid config file, try to be helpful instead

This commit is contained in:
Ben Kimock
2019-03-03 13:14:15 -05:00
parent 28c76f7462
commit c23956bcbd
3 changed files with 29 additions and 25 deletions

View File

@@ -1,19 +1,7 @@
use std::fs::File;
use std::io::prelude::*;
pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Config {
pub username: String,
pub password: String,
}
pub fn load(filename: &str) -> Result<Config, toml::de::Error> {
let mut f = File::open(filename).expect("ncspot configuration file not found");
let mut contents = String::new();
f.read_to_string(&mut contents)
.expect("something went wrong reading the file");
toml::from_str(&contents)
}