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

Invalid type with serde(flatten) and u32 #32

Closed
nanocryk opened this issue Dec 4, 2019 · 2 comments
Closed

Invalid type with serde(flatten) and u32 #32

nanocryk opened this issue Dec 4, 2019 · 2 comments

Comments

@nanocryk
Copy link

nanocryk commented Dec 4, 2019

with dotenv = "0.15.0"

#[derive(Deserialize)]
pub struct Config {
    pub var: u32
}

works, but

#[derive(Deserialize)]
pub struct Config {
    #[serde(flatten)]
    pub sub: Sub,
}

#[derive(Deserialize)]
pub struct Sub {
    pub var: u32
}

gives an error at runtime :

Error: Custom("invalid type: string \"0\", expected u32")
@ZoeyR
Copy link
Contributor

ZoeyR commented Dec 4, 2019

I'm confused, are you saying that merely having dotenv as a dependency is breaking serde?

@nanocryk
Copy link
Author

nanocryk commented Dec 5, 2019

No, I deserialize my .env file with dotenv::dotenv()?.
With a flat structure it works, but using [serde(flatten)] it no longer works.

EDIT: Oops, I though dotenv was responsible for der variables into a struct while it's the envy crate. Sorry.

softprops/envy#26

@nanocryk nanocryk closed this as completed Dec 5, 2019
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

2 participants