rust-cli / rust-cli/config-rs

"with_list_parse_key" environment parser does not support vector field

Open
#648 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-env C-enhancement S-waiting-on-design
Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

Not sure if I doing it wrongly or misunderstand the source code, the with_list_parse_key option is creating a map that will be used to check if a field should use list parser. In the case of vector of struct that contains vector field it is not possible to specify the key unless we specify all the possible index.

struct Nested {
    pub keys: Vec<String>,
}

struct Config {
    pub nested: Vec<Nested>
}

let env_source = Environment::with_prefix("server_config")
        .list_separator(",")
        // note: need to list all the possible index
        .with_list_parse_key("nested[0].keys")
        .with_list_parse_key("nested[1].keys")
        .try_parsing(true);

Is this the expected behaviour or could it be possible to support key like nested[*].keys?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Environment::with_list_parse_key entry point and trace how its keys are matched by the environment list parser. Reproduce the nested vector-of-struct example, then determine the expected wildcard behavior and add coverage showing that nested[*].keys handles vector fields without enumerating indexes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.