Skip to main content

modo/config/
env.rs

1use std::env as std_env;
2
3const APP_ENV_KEY: &str = "APP_ENV";
4const DEFAULT_ENV: &str = "development";
5
6/// Returns the current application environment.
7///
8/// Reads the `APP_ENV` environment variable. Falls back to `"development"` when
9/// the variable is not set.
10pub fn env() -> String {
11    std_env::var(APP_ENV_KEY).unwrap_or_else(|_| DEFAULT_ENV.to_string())
12}
13
14/// Returns `true` when `APP_ENV` is `"development"` (or unset).
15pub fn is_dev() -> bool {
16    env() == "development"
17}
18
19/// Returns `true` when `APP_ENV` is `"production"`.
20pub fn is_prod() -> bool {
21    env() == "production"
22}
23
24/// Returns `true` when `APP_ENV` is `"test"`.
25pub fn is_test() -> bool {
26    env() == "test"
27}