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

Rename a field to a word consists of capitals only #42

Closed
ANtlord opened this issue Jul 28, 2019 · 3 comments
Closed

Rename a field to a word consists of capitals only #42

ANtlord opened this issue Jul 28, 2019 · 3 comments

Comments

@ANtlord
Copy link

ANtlord commented Jul 28, 2019

🐛 Bug description

Parsing finishes with error Error::MissingValue if I rename a field of parsed structure to a word consists of capitals only.

🤔 Expected Behavior

Should be parsed without errors.

👟 Steps to reproduce

Define structure for parsing

#[derive(Deserialize, Debug)]
pub struct DB {
    #[serde(rename="DB_USER")]
    pub user: String,
    #[serde(rename="DB_PASS")]
    pub pass: String,
    #[serde(rename="DB_NAME")]
    pub name: String,
    #[serde(default="host", rename="DB_HOST")]
    pub host: String,
    #[serde(default="port", rename="DB_PORT")]
    pub port: u16,
}

let db_config = envy::from_env::<settings::DB>().unwrap();

Make export DB_USER=postgres before running, run and get panic value: MissingValue("DB_USER")

🌍 Your environment

Archlinux

envy version:
0.4.0

So. I see this code in lib.rs

impl<Iter: Iterator<Item = (String, String)>> Iterator for Vars<Iter> {
    type Item = (VarName, Val);

    fn next(&mut self) -> Option<Self::Item> {
        self.0
            .next()
            .map(|(k, v)| (VarName(k.to_lowercase()), Val(k, v)))
    }
}

So I understand why the k is got lowercased. I get the expected behavior if I remove this conversion but it's not a solution because I lose feature of automatic comparison of a field of parsed structure and an environment variable. So my question is how to determine if a field has Serde tag rename? I can use the determining in order to prevent the conversion only for "renamed" fields.

@tosti007
Copy link

I experience the same issue. A different Steps to reproduce would be to copy the example of the README.md and add a rename attribute to any of the variables, e.g.#[serde(rename="baz")] to the baz variable.

@ANtlord
Copy link
Author

ANtlord commented Mar 17, 2020

The issue is opened 9 months ago. I suppose it's not easy to fix it. I tried another library which doesn't have issue but has another one which is resolved in this one. Well, I fixed both of the issues in my fork of that library.

@ardyfeb
Copy link

ardyfeb commented Dec 14, 2021

this library doesn't work anymore

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

3 participants