summaryrefslogtreecommitdiffstats
path: root/examples/env-list/main.rs
blob: f567419b549b9b1eb0347034520617285d47007d (plain)
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
use config::Config;
#[derive(Debug, Default, serde_derive::Deserialize, PartialEq)]
struct AppConfig {
    list: Vec<String>,
}

fn main() {
    std::env::set_var("APP_LIST", "Hello World");

    let config = Config::builder()
        .add_source(
            config::Environment::with_prefix("APP")
                .try_parsing(true)
                .separator("_")
                .list_separator(" "),
        )
        .build()
        .unwrap();

    let app: AppConfig = config.try_deserialize().unwrap();

    assert_eq!(app.list, vec![String::from("Hello"), String::from("World")]);

    std::env::remove_var("APP_LIST");
}