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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use DeserializeOwned;
use Path;
use env;
use substitute_env_vars;
use crateResult;
/// Loads and deserializes a YAML config file for the current environment.
///
/// The file is resolved as `{config_dir}/{APP_ENV}.yaml`, where `APP_ENV` is
/// read from the process environment via [`super::env()`] (defaults to
/// `"development"`). After reading, all `${VAR}` and `${VAR:default}`
/// placeholders are replaced with values from the process environment via
/// [`substitute_env_vars`] before YAML deserialization with `serde_yaml_ng`.
///
/// `T` may be [`crate::Config`] or any application-specific struct — flatten
/// `Config` with `#[serde(flatten)]` to keep the framework fields alongside
/// custom ones.
///
/// # Errors
///
/// Returns [`crate::Error`] when:
/// - The config file cannot be read (missing file, permission denied, …).
/// - A required `${VAR}` placeholder references an unset environment variable
/// and provides no default.
/// - A `${...` placeholder is unclosed.
/// - The YAML cannot be deserialized into `T`.
///
/// # Example
///
/// ```no_run
/// use modo::config::load;
/// use modo::Config;
///
/// let config: Config = load("config/").unwrap();
/// ```