Added command line to find config

This commit is contained in:
int 80h
2020-04-28 17:54:50 -04:00
parent 596783d613
commit 6a118ad66a
3 changed files with 17 additions and 18 deletions

View File

@@ -2,6 +2,8 @@ extern crate serde_derive;
extern crate toml;
use std::collections::HashMap;
use toml::de::Error;
use std::io;
use std::path::Path;
#[derive(Debug, Deserialize, Clone)]
pub struct Config {
@@ -20,10 +22,10 @@ pub struct Server {
}
impl Config {
pub fn new(file: &str) -> Config {
pub fn new(file: &Path) -> Result<Config, Error> {
let fd = std::fs::read_to_string(file).unwrap();
let config: Config = toml::from_str(&fd).unwrap();
return config;
return Ok(config);
}
pub fn to_map(&self) -> HashMap<String, Server> {
let mut map = HashMap::new();