Skip to content

Add "separator" to parse nested structs #55

Open
@dbofmmbt

Description

💡 Feature description

In config-rs, there's an option to define a separator which allow users to structure their env vars. I think an example will illustrate better:

#[derive(Deserialize)]
struct Config {
    database: Database
}

#[derive(Deserialize)]
struct Database {
    name: String,
}

If we define a separator, let's say "__", we could create this Config by setting DATABASE__NAME=foo.

Would it be possible and desirable for envy to include it?

Alternatives

It is possible to get the same behavior using the flatten attribute from serde (as noticed in #15). The drawback is that it demands a good amount of boilerplate because we would have to serde's rename every field in the nested struct if we wanted to use this separator idea.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions