Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Field defaults overwrite explicitly selected unit enum variants

未关闭
#511 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

Start at the derived Configuration implementation for enums and inspect how contains_non_secret_data() treats unit variants. Add a regression test using the issue’s LogFormat example and field default. Done means the explicitly configured Json value survives try_build() instead of being replaced by Plain.

由索引模型根据 Issue 内容生成。

描述

The Configuration derive returns false from contains_non_secret_data() for unit enum variants. This causes #[confik(default = …)] to overwrite explicit values—for example, configured LogFormat::Json becomes the default LogFormat::Plain.

An explicitly selected variant should count as supplied data and take precedence over the field default.

This works:

// Cargo.toml:
// confik = "=0.15.12"
// serde = { version = "1", features = ["derive"] }

use confik::{Configuration, TomlSource};

#[derive(Debug, PartialEq, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
enum LogFormat {
    Plain,
    Json,
}

impl Configuration for LogFormat {
    type Builder = Option<Self>;
}

#[derive(Configuration)]
struct Config {
    #[confik(default = LogFormat::Plain)]
    format: LogFormat,
}

fn main() {
    let config = Config::builder()
        .override_with(TomlSource::new(r#"format = "json""#))
        .try_build()
        .unwrap();

    assert_eq!(config.format, LogFormat::Json);
}

This doesn’t — a derived implementation with the same field default:

// Cargo.toml: confik = "=0.15.12"

use confik::{Configuration, TomlSource};

#[derive(Debug, PartialEq, Configuration)]
#[confik(forward(serde(rename_all = "lowercase")))]
enum LogFormat {
    Plain,
    Json,
}

#[derive(Configuration)]
struct Config {
    #[confik(default = LogFormat::Plain)]
    format: LogFormat,
}

fn main() {
    let config = Config::builder()
        .override_with(TomlSource::new(r#"format = "json""#))
        .try_build()
        .unwrap();

    // Fails: left is Plain, right is Json.
    assert_eq!(config.format, LogFormat::Json);
}
主要语言
Rust
星标
46
派生
3
平均合并
19 小时 35 分钟
30 天内合并 PR
27

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

x52dev/confik 的其他 Issue

查看 x52dev/confik 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。