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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crateConfigError;
/// A trait for types that can be loaded from environment variables.
///
/// This trait is typically implemented automatically using the `#[derive(Config)]` macro.
/// The generated implementation reads environment variables based on `#[env]` attributes,
/// applies default values from `#[default]` attributes, and handles nested configurations
/// marked with `#[config]`.
///
/// # Examples
///
/// ```rust
/// use tryphon::Config;
///
/// #[derive(Config)]
/// struct AppConfig {
/// #[env("DATABASE_URL")]
/// database_url: String,
///
/// #[env("PORT")]
/// #[default(8080)]
/// port: u16,
/// }
///
/// # unsafe { std::env::set_var("DATABASE_URL", "postgres://localhost/mydb"); }
/// let config = AppConfig::load().expect("Failed to load config");
/// assert_eq!(config.port, 8080);
/// ```
///
/// # Error Handling
///
/// The `load()` method returns a [`ConfigError`] which contains all field errors
/// encountered during loading. This allows you to see all configuration problems
/// at once rather than failing on the first error.
///
/// ```rust
/// use tryphon::Config;
///
/// #[derive(Config)]
/// struct AppConfig {
/// #[env("REQUIRED_VAR")]
/// required: String,
///
/// #[env("PORT")]
/// port: u16,
/// }
///
/// match AppConfig::load() {
/// Ok(config) => { /* use config */ }
/// Err(e) => {
/// eprintln!("Configuration errors:");
/// for error in &e.field_errors {
/// eprintln!(" - {:?}", error);
/// }
/// }
/// }
/// ```