diff options
author | simon-an <26556185+simon-an@users.noreply.github.com> | 2022-02-28 18:14:36 +0100 |
---|---|---|
committer | simon-an <26556185+simon-an@users.noreply.github.com> | 2022-02-28 18:18:37 +0100 |
commit | 53322d4ca277a2e55a7efeb654e400e5c05eb672 (patch) | |
tree | 08ee0506ba46a4ad6e25330b20b07558374b0603 /examples | |
parent | 92e29a3c1351f9a8f1c7e1fd752d9c2b4d6ee2b4 (diff) |
feat: env contains list of strings
Signed-off-by: simon-an <26556185+simon-an@users.noreply.github.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/env-list/main.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/env-list/main.rs b/examples/env-list/main.rs new file mode 100644 index 0000000..f567419 --- /dev/null +++ b/examples/env-list/main.rs @@ -0,0 +1,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"); +} |