Environment Variable List of Structs
Enables specifying lists of structs within environment variables.
Example
#[derive(Deserialize, Debug, PartialEq)]
struct Struct {
a: Vec<Option<u32>>,
b: u32,
}
#[derive(Deserialize, Debug)]
struct ListOfStructs {
list: Vec<Struct>,
}
let values = vec![
("LIST_0_A_0".to_owned(), "1".to_owned()),
("LIST_0_A_2".to_owned(), "2".to_owned()),
("LIST_0_B".to_owned(), "3".to_owned()),
("LIST_1_A_1".to_owned(), "4".to_owned()),
("LIST_1_B".to_owned(), "5".to_owned()),
];
let environment = Environment::default()
.separator("_")
.try_parsing(true)
.source(Some(values.into_iter().collect()));
let config = Config::builder().add_source(environment).build().unwrap();
let config: ListOfStructs = config.try_deserialize().unwrap();
assert_eq!(
config.list,
vec![
Struct {
a: vec![Some(1), None, Some(2)],
b: 3
},
Struct {
a: vec![None, Some(4)],
b: 5
},
]
);
closes #603
No breaking changes in this PR, should be fully backward compatible.
@epage or @matthiasbeyer any chance I could get one of you to take a look?
Sorry, I had forgotten to change my watch status for this repo.
My general approach is that PRs should not be reviewed, or generally posted, until use cases and requirements are understood and we've agreed to a design. See also https://github.com/rust-cli/config-rs/blob/main/CONTRIBUTING.md#pull-requests
Pull Request Test Coverage Report for Build 11611055215
Warning: This coverage report may be inaccurate.
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
- For more information on this, see Tracking coverage changes with pull request builds.
- To avoid this issue with future PRs, see these Recommended CI Configurations.
- For a quick fix, rebase this PR at GitHub. Your next report should be accurate.
Details
- 53 of 53 (100.0%) changed or added relevant lines in 2 files are covered.
- 1 unchanged line in 1 file lost coverage.
- Overall coverage increased (+1.4%) to 64.416%
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| src/value.rs | 1 | 40.18% |
| <!-- | Total: | 1 |
| Totals | |
|---|---|
| Change from base Build 11488444135: | 1.4% |
| Covered Lines: | 992 |
| Relevant Lines: | 1540 |
💛 - Coveralls
@epage sounds good to me. I needed this change on my personal fork anyhow. I posted an issue here a couple weeks ago. Happy to discuss any design changes you'd like to see there.