Open hal8888 opened 1 year ago
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 fieldapp_version``
value: missing field
If I change with serde rename I got: value: missing field VERSION
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.
VERSION
version
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.
Im expecting to put alias to each fields in a struct where the alias name are the keys from os env
in my os env:
When I build with:
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
toversion
, but I need way to map this.How to map easily from os env with different keys name to structs with different keys name?