adding comments in config.rs

This commit is contained in:
neil 2020-09-16 22:08:19 +02:00
parent 6a9465d579
commit 5bf70566ac
1 changed files with 6 additions and 0 deletions

View File

@ -24,6 +24,7 @@ lazy_static! {
pub static ref LOC: Value = init_lang();
}
// Open LOC_FILE and store it in memory (LOC)
fn init_lang() -> Value {
let mut file = File::open(LOC_FILE).expect("init_lang: Can't open translations file");
let mut data = String::new();
@ -32,6 +33,7 @@ fn init_lang() -> Value {
serde_json::from_str(&data).expect("init_lang(): Can't parse translations file")
}
// Open a file from its path
fn lines_from_file(filename: impl AsRef<Path>) -> io::Result<Vec<String>> {
BufReader::new(File::open(filename)?).lines().collect()
}
@ -52,6 +54,7 @@ pub struct Config {
// totally not copypasted from rs-short
impl Config {
// open and parse CONFIG_FILE
pub fn init() -> Self {
let mut conffile = File::open(CONFIG_FILE).expect(
r#"Config file config.toml not found.
@ -63,6 +66,9 @@ impl Config {
.expect("Couldn't read config to string");
toml::from_str(&confstr).expect("Couldn't deserialize the config")
}
// if config.config_version doesn't match the hardcoded version,
// ask the admin to manually upgrade its config file
pub fn check_version(&self) {
if self.config_version != CONFIG_VERSION {
eprintln!("Your configuration file is obsolete!\nPlease update it following the instructions in https://git.42l.fr/neil/sncf/wiki/Upgrade-from-a-previous-version and update its version to {}.", CONFIG_VERSION);