Changed reader to return custom struct

main
David 2022-11-08 21:02:32 +01:00
parent 5895795e14
commit 9aba44b8f4
1 changed files with 10 additions and 6 deletions

View File

@ -2,14 +2,18 @@ pub mod config_reader {
use std::error::Error;
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 _map = config.load("../../matrix_creds.ini")?;
let _map = config.load(file_path)?;
let user_id = config.get("credentials", "userid").unwrap();
let password = config.get("credentials", "password").unwrap();
let mut return_vec: Vec<String> = vec![];
return_vec.push(user_id);
return_vec.push(password);
return Ok(return_vec)
Ok(BotUserCreds{user_id, password})
}
}