We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi! I'm trying to overwrite a variable in toml with env variable. Due to restrictions w.r.t underscores, I had to alias a field with serde.
config::{Config, ConfigError, File, Environment}; use serde::{Serialize, Deserialize}; #[derive(Debug, Deserialize, Clone)] pub struct Settings { pub name: String, pub v4: TlsConfig, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct TlsConfig { pub ca_path: String, #[serde(alias = "certpath")] pub cert_path: String, // #[serde(alias = "keypath")] pub key_path: String, } pub fn main() -> Result<(), ConfigError> { std::env::set_var("V4_CERTPATH", "Hello World"); let s = Config::builder() .add_source(File::with_name("default.toml")) .add_source(Environment::default().separator("_")) .build()?; dbg!(&s); let v: Settings = s.try_deserialize()?; dbg!(v); Ok(()) }
This is leading go this error
Error: duplicate field `cert_path`
How do I fix this?
The text was updated successfully, but these errors were encountered:
Interesting! I filed a PR that adds (and hopefully fixes at some point) a test for this in #370
Sorry, something went wrong.
I think I found a reasonable workaround: use "__" (2 '_') as separator. That way the nested struct are appropriately set.
"__"
'_'
Okay, I'll close this then. Thanks for reporting back!
Thanks for reporting back!
That wasn't the original reporter btw.
No branches or pull requests
Hi! I'm trying to overwrite a variable in toml with env variable. Due to restrictions w.r.t underscores, I had to alias a field with serde.
This is leading go this error
How do I fix this?
The text was updated successfully, but these errors were encountered: