Field defaults overwrite explicitly selected unit enum variants
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
x52dev/confik 的其他 Issue
-
bug-upstream
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
维护者通常 1 天内回复
相似的 Issue
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 72/100
servo/rust-smallvec#827 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
nowledge-co/hawdb#1400 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
calcit-lang/caps#16 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
penso/herdr-gpui#934 ·
维护者通常 1 天内回复
-
🎉 Add Bossanova未关闭
难度 2/5 1-3 小时 新手友好度 70/100
jaywcjlove/awesome-mac#4096 ·
维护者通常 1 天内回复