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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't handle capitalised rename #61

Closed
hottea773 opened this issue May 26, 2021 · 1 comment 路 Fixed by #72 路 May be fixed by #69
Closed

Can't handle capitalised rename #61

hottea773 opened this issue May 26, 2021 · 1 comment 路 Fixed by #72 路 May be fixed by #69

Comments

@hottea773
Copy link

hottea773 commented May 26, 2021

馃悰 Bug description

Given the following main.rs:

#[derive(serde::Deserialize, Clone, Debug, serde::Serialize)]
pub struct Person {
    #[serde(rename(deserialize = "surname"))]
    pub surname: String,
    #[serde(skip_serializing, rename(deserialize = "FIRST_NAME"))]
    pub first_name: String,
}


fn main() -> anyhow::Result<()> {

    println!("FIRST_NAME: {}", std::env::var("FIRST_NAME").unwrap());
    println!("surname: {}", std::env::var("surname").unwrap());

    let person = envy::from_env::<Person>().map_err(|e| {
        anyhow::anyhow!(e).context("Could not read Person from environment")
    })?;

    println!("Person: {:?}", person);

    Ok(())
}

it fails to read the FIRST_NAME environment variable:

$ surname=smith FIRST_NAME=john cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/envy_bug`
FIRST_NAME: john
surname: smith
Error: Could not Person from environment

Caused by:
    missing value for field FIRST_NAME

馃 Expected Behavior

It should have been able to read the FIRST_NAME environment variable.

馃憻 Steps to reproduce

Run the above code.

馃實 Your environment

I used the following Cargo.toml:

[package]
name = "envy_bug"
version = "0.1.0"
authors = ["hottomato4"]
edition = "2018"
publish = ["github"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

serde = { version = "1", features = [ "derive" ] }
envy = "0.4"
anyhow = "1"

and the following Cargo.lock

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "anyhow"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"

[[package]]
name = "envy"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965"
dependencies = [
 "serde",
]

[[package]]
name = "envy_bug"
version = "0.1.0"
dependencies = [
 "anyhow",
 "envy",
 "serde",
]

[[package]]
name = "proc-macro2"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
 "unicode-xid",
]

[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "serde"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "syn"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-xid",
]

[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "anyhow"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"

[[package]]
name = "envy"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965"
dependencies = [
 "serde",
]

[[package]]
name = "envy_bug"
version = "0.1.0"
dependencies = [
 "anyhow",
 "envy",
 "serde",
]

[[package]]
name = "proc-macro2"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
 "unicode-xid",
]

[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "serde"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "syn"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-xid",
]

[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

Also:

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /opt/rust

installed targets for active toolchain
--------------------------------------

x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.52.1 (9bc8c42bb 2021-05-09)
$ cargo --version
cargo 1.52.0 (69767412a 2021-04-21)
@alakhpc
Copy link

alakhpc commented Jul 28, 2022

Is there any solution for this yet? seems like this is still there

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