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
/// A trait for decoding raw string values from environment variables into typed values.
///
/// This trait defines how to convert a raw string value from an environment variable
/// into a specific Rust type. Implement this trait to support custom types in your
/// configuration structs.
///
/// # Examples
///
/// ## Simple Custom Type
///
/// ```rust
/// use tryphon::{ConfigValueDecoder, Config};
///
/// #[derive(Debug, PartialEq)]
/// enum Environment {
/// Development,
/// Staging,
/// Production,
/// }
///
/// impl ConfigValueDecoder for Environment {
/// fn decode(raw: String) -> Result<Self, String> {
/// match raw.to_lowercase().as_str() {
/// "dev" | "development" => Ok(Environment::Development),
/// "staging" => Ok(Environment::Staging),
/// "prod" | "production" => Ok(Environment::Production),
/// _ => Err(format!("Unknown environment: {}", raw))
/// }
/// }
/// }
///
/// #[derive(Config)]
/// struct AppConfig {
/// #[env("ENV")]
/// environment: Environment,
/// }
///
/// # unsafe { std::env::set_var("ENV", "production"); }
/// # let config = AppConfig::load().unwrap();
/// # assert_eq!(config.environment, Environment::Production);
/// ```
///