Closed
Description
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?
Metadata
Metadata
Assignees
Labels
No labels