Changed reader to return custom struct
parent
5895795e14
commit
9aba44b8f4
|
@ -2,14 +2,18 @@ pub mod config_reader {
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use configparser::ini::Ini;
|
use configparser::ini::Ini;
|
||||||
|
|
||||||
pub fn read_configs() -> Result<Vec<String>, Box<dyn Error>> {
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct BotUserCreds {
|
||||||
|
user_id: String,
|
||||||
|
password: String
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_configs(file_path: &str) -> Result<BotUserCreds, Box<dyn Error>> {
|
||||||
let mut config = Ini::new();
|
let mut config = Ini::new();
|
||||||
let _map = config.load("../../matrix_creds.ini")?;
|
let _map = config.load(file_path)?;
|
||||||
let user_id = config.get("credentials", "userid").unwrap();
|
let user_id = config.get("credentials", "userid").unwrap();
|
||||||
let password = config.get("credentials", "password").unwrap();
|
let password = config.get("credentials", "password").unwrap();
|
||||||
let mut return_vec: Vec<String> = vec![];
|
Ok(BotUserCreds{user_id, password})
|
||||||
return_vec.push(user_id);
|
|
||||||
return_vec.push(password);
|
|
||||||
return Ok(return_vec)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue