rust-cli / rust-cli/config-rs

Enum variant aliases don't work

Open
#502 3 comments 3 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

Here is a failing example demonstrating that enum variant aliases are not taken into account. It also shows a divergence in behavior compared to using serde_json directly.

#[derive(Debug, serde::Deserialize)]
enum TestEnum {
    #[serde(alias = "f")]
    Foo,
    #[serde(alias = "b")]
    Bar,
}

#[derive(Debug, serde::Deserialize)]
struct Wrapper {
    test: TestEnum,
}

let json = r#"{"test": "f"}"#;
let w: Wrapper = serde_json::from_str(json).unwrap();
println!("{:?}", w);
let w: Wrapper = config::Config::builder()
    .add_source(config::File::from_str(json, config::FileFormat::Json))
    .build()
    .unwrap()
    .try_deserialize()
    .unwrap();
println!("{:?}", w);

Output:

Wrapper { t: Foo }
called `Result::unwrap()` on an `Err` value: enum TestEnum does not have variant constructor f

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

Start with the failing Rust example and compare the serde_json deserialization path with config::Config::builder(), especially the JSON source and try_deserialize steps. Trace how enum variant names are resolved; done means serde aliases such as "f" and "b" deserialize through config as they do with serde_json.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.