Skip to content
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

Mapping options to nested structs #11

Closed
clintjedwards opened this issue Jun 18, 2022 · 1 comment
Closed

Mapping options to nested structs #11

clintjedwards opened this issue Jun 18, 2022 · 1 comment

Comments

@clintjedwards
Copy link

Hey! I love how simple this library is and wanted to use it on something I'm writing. I came across something I got confused about and wanted to know if there was a way I wasn't immediately obvious to.

Specifically, I have an option value that I would expect to get parsed in a bit different of a way:

For example, I have:

#[derive(Debug, Default, econf::LoadEnv, PartialEq, Eq)]
struct Config {
    simple_value: String,
    config: Option<InnerConfig>,
}

#[derive(Debug, Default, econf::LoadEnv, serde::Deserialize, PartialEq, Eq)]
struct InnerConfig {
    inner_value: String,
}

fn main() {
    let config = Config::default();

    std::env::set_var("TEST_SIMPLE_VALUE", "test_value");
    std::env::set_var("TEST_CONFIG", r#"{inner_value: "test_value"}"#);

    let expected_config = Config {
        simple_value: "test_value".to_string(),
        config: Some(InnerConfig {
            inner_value: "test_value".to_string(),
        }),
    };
    let parsed_config = econf::load(config, "TEST");

    assert_eq!(expected_config, parsed_config);

    std::env::remove_var("TEST_SIMPLE_VALUE");
    std::env::remove_var("TEST_CONFIG");
}

Specifically for parsing of config: Option<InnerConfig>, while I understand why it works the way it does due to the documentation:

Instead of this:

std::env::set_var("TEST_CONFIG", r#"{inner_value: "test_value"}"#);

I would love to be able to do this:

std::env::set_var("TEST_CONFIG_INNER_VALUE", "test_value"});

Is there a current way to do this? Also willing to contribute and add this functionality if you point me to the right places and think it's a doable feature.

@clintjedwards clintjedwards changed the title Mapping options correctly Mapping options to nested structs Jun 18, 2022
@clintjedwards
Copy link
Author

Closing since no response.

@clintjedwards clintjedwards closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant