Skip to content

"with_list_parse_key" environment parser does not support vector field #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TAYTS opened this issue Mar 7, 2025 · 2 comments
Open

Comments

@TAYTS
Copy link

TAYTS commented Mar 7, 2025

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?

@epage
Copy link
Contributor

epage commented Mar 7, 2025

Currently, we only have one path syntax. The question would be whether we should only support wildcards here or if we could make it work to support wildcards in most places that take a path (and error otherwise). Should we also support this for keys?

I would lean towards general wildcard support. My maintenance of this crate is more passive, so someone wanting to see this done will need to take an active hand in investigating this and proposing a design (e.g. where all does path syntax apply, whether it makes sense to take a wildcard, what the behavior would be, the feasibility of meeting that behavior).

@TAYTS
Copy link
Author

TAYTS commented Mar 8, 2025

Let me try understand the codebase better and propose the solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants