blob: 518a82a74a6021982a8c5569fe1e66506efb3ce5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use std::{fs::File, io::{Read, read_to_string}, path::Path};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct Config {
}
pub const DEFAULT_CONFIG_FILE_LOCATIONS: [&str; 1] = [
"/etc/rss-aggregator.toml",
];
impl Config {
pub fn parse_config_file_at_path(path: &str) -> anyhow::Result<Config> {
let path = Path::new(path);
let file = File::open(&path)?;
let contents = read_to_string(file)?;
Ok(toml::from_str(&contents)?)
}
pub fn find_config() -> Option<Config> {
for path in DEFAULT_CONFIG_FILE_LOCATIONS {
match Self::parse_config_file_at_path(path) {
Ok(config) => { return Some(config); },
Err(_) => {},
};
};
None
}
}
|