importer/
configuration.rs

1use serde::Deserialize;
2
3#[derive(Deserialize)]
4#[serde(default)]
5pub struct ImporterConfiguration {
6    pub osmium: String,
7    pub unzip: String,
8    pub gunzip: String,
9    pub gunzip_args: String,
10}
11
12impl Default for ImporterConfiguration {
13    fn default() -> ImporterConfiguration {
14        ImporterConfiguration {
15            osmium: String::from("osmium"),
16            unzip: String::from("unzip"),
17            gunzip: String::from("gunzip"),
18            gunzip_args: String::from(""),
19        }
20    }
21}
22
23impl ImporterConfiguration {
24    pub fn load() -> Self {
25        // Safe to assume that {} can be parsed given struct-level Default implementation.
26        let default = serde_json::from_str("{}").unwrap();
27
28        match fs_err::read_to_string("importer.json") {
29            Ok(contents) => serde_json::from_str(&contents).unwrap_or(default),
30            Err(_) => default,
31        }
32    }
33}