gist/
config.rs

1use std::fs;
2
3const CONFIG_FILE: &'static str = "config.json";
4
5#[derive(Serialize, Deserialize, Debug)]
6pub struct Config {
7    pub gist_token: String,
8}
9
10impl Config {
11    pub fn read() -> Option<Self> {
12        if let Some(config_path) = dirs_next::home_dir().map(|home_dir| {
13            home_dir
14                .join(format!(".{}", env!("CARGO_PKG_NAME")))
15                .join(CONFIG_FILE)
16        }) {
17            if let Ok(contents) = fs::read_to_string(config_path) {
18                return serde_json::from_str(&contents).ok();
19            }
20        }
21        None
22    }
23}