We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4c1193 commit fec6a4aCopy full SHA for fec6a4a
examples/static_env.rs
@@ -0,0 +1,20 @@
1
+use config::Config;
2
+
3
+lazy_static::lazy_static! {
4
+ #[derive(Debug)]
5
+ pub static ref CONFIG: Config = Config::builder()
6
+ .add_source(config::Environment::with_prefix("APP_NAME").separator("_"))
7
+ .build()
8
+ .unwrap();
9
+}
10
11
+/// Get a configuration value from the static configuration object
12
+pub fn get<'a, T: serde::Deserialize<'a>>(key: &str) -> T {
13
+ // You shouldn't probably do it like that and actually handle that error that might happen
14
+ // here, but for the sake of simplicity, we do it like this here
15
+ CONFIG.get::<T>(key).unwrap()
16
17
18
+fn main() {
19
+ println!("{:?}", get::<String>("foo"));
20
0 commit comments