config.rs (630B)
1 use color_eyre::eyre::Result; 2 use serde::{Deserialize, Serialize}; 3 use std::borrow::Cow; 4 use std::{fs, path::Path}; 5 use tracing::*; 6 7 #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] 8 pub struct Config<'a> { 9 pub homeserver_url: Cow<'a, str>, 10 pub mxid: Cow<'a, str>, 11 pub password: Cow<'a, str>, 12 pub store_path: Cow<'a, str>, 13 } 14 15 impl Config<'_> { 16 #[instrument] 17 pub fn load() -> Result<Self> { 18 let contents = 19 fs::read_to_string("./config.yml").expect("Something went wrong reading the file"); 20 let config: Self = serde_yaml::from_str(&contents)?; 21 Ok(config) 22 } 23 }