From f8a6987fcf477b7e57cd41d3cd6cc1f48b367b61 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sun, 2 Nov 2014 13:32:02 -0500 Subject: [PATCH] Config::load(...) now takes the path to the configuration file. --- src/bot.rs | 4 ++-- src/data.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index ccd3801..775a280 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -14,7 +14,7 @@ pub struct IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader { impl<'a> IrcBot<'a, BufferedWriter, BufferedReader> { pub fn new(process: |&IrcBot, BufferedReader>, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult, BufferedReader>> { - let config = try!(Config::load()); + let config = try!(Config::load("config.json")); let conn = try!(Connection::connect(config.server[], config.port)); Ok(IrcBot { conn: conn, @@ -123,7 +123,7 @@ impl<'a, T, U> IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader { pub fn from_connection(conn: Connection, process: |&IrcBot, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult> { Ok(IrcBot { conn: conn, - config: try!(Config::load()), + config: try!(Config::load("config.json")), process: RefCell::new(process), chanlists: RefCell::new(HashMap::new()), }) diff --git a/src/data.rs b/src/data.rs index 8cd1164..89ce853 100644 --- a/src/data.rs +++ b/src/data.rs @@ -86,8 +86,8 @@ pub struct Config { } impl Config { - pub fn load() -> IoResult { - let mut file = try!(File::open(&Path::new("config.json"))); + pub fn load(path: &str) -> IoResult { + let mut file = try!(File::open(&Path::new(path))); let data = try!(file.read_to_string()); decode(data[]).map_err(|e| IoError { kind: InvalidInput, @@ -119,12 +119,12 @@ mod test { #[test] fn load_config() { - assert!(Config::load().is_ok()); + assert!(Config::load("config.json").is_ok()); } #[test] fn is_owner() { - let cfg = Config::load().unwrap(); + let cfg = Config::load("config.json").unwrap(); assert!(cfg.is_owner("test")); assert!(!cfg.is_owner("test2")); }