config-rs
config-rs copied to clipboard
Serde alias not working
Im expecting to put alias to each fields in a struct where the alias name are the keys from os env
#[derive(Debug, Deserialize, Clone)]
pub struct BuildInfo {
#[serde(alias = "VERSION")]
pub app_version: String,
}
in my os env:
VERSION=1.2.3
When I build with:
let builder = Config::builder().add_source(Environment::default()).build();
builder.unwrap().try_deserialize::<BuildInfo>().unwrap()
I got panic error: value: missing field app_version``
If I change with serde rename I got:
value: missing field VERSION
it works if I just change the letter case like from VERSION to version, but I need way to map this.
How to map easily from os env with different keys name to structs with different keys name?
It seems that aliasing doesn't work with os envs. It works for other kind of file formats.