1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use std::env;

#[derive(Clone, Debug)]
pub struct Config {
    pub enable_backup: bool,
}

impl Default for Config {
    fn default() -> Self {
        Self {
            enable_backup: from_env_default("ENABLE_BACKUP", "true").parse().unwrap(),
        }
    }
}

// Source the variable from the env - use default if not set
fn from_env_default(var: &str, default: &str) -> String {
    env::var(var).unwrap_or_else(|_| default.to_owned())
}