rust-cli / rust-cli/config-rs

Serde alias not working

Open
#384 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown BuildInfo struct, VERSION environment variable, and Environment source. Trace how environment keys are normalized and passed to serde, then verify that the intended mapping from VERSION to app_version is either supported or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.