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
use std::collections::HashMap;
use lazy_static::*;
use config::{Config, File, FileFormat};

pub mod models;
pub mod filters;
pub mod handlers;
pub mod todo_server;
pub mod log;
pub mod db;

// initialize: application settings 
lazy_static!{
    // pull-in todo specific settings from Settings.toml 
    static ref SETTINGS: HashMap<String, String> = get_settings();
}

// Extract Todo Specific settings from Settings.toml
fn get_settings() -> HashMap<String, String> {
    let mut config = Config::default();
    config.merge(File::new("Settings", FileFormat::Toml)).unwrap();
    let settings = config.try_into::<HashMap<String, String>>().unwrap(); // Deserialize entire file contents
    settings
}

pub fn config(key: &str) -> String {
    SETTINGS.get(key).unwrap().to_string()
}